Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return completions in alphanumeric order #57742

Closed
AnandaArya opened this issue Mar 7, 2024 · 9 comments · Fixed by #57745
Closed

Return completions in alphanumeric order #57742

AnandaArya opened this issue Mar 7, 2024 · 9 comments · Fixed by #57745
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Milestone

Comments

@AnandaArya
Copy link

Hello, I'm working with TypeScript in Visual Studio Code and I've noticed that the autocomplete suggestions for union types are not displayed in a logical order. Specifically, I have a union type for column sizes in a grid layout system:

image

@mjbvz mjbvz assigned jrieken and unassigned mjbvz Mar 7, 2024
@mjbvz
Copy link
Contributor

mjbvz commented Mar 7, 2024

Please share a complete, self contained code example as text

@mjbvz mjbvz self-assigned this Mar 7, 2024
@AnandaArya
Copy link
Author

Please share a complete, self contained code example as text

here's complete code

import { twMerge } from "tailwind-merge";
import { cn } from "../../../utils/tailwind";
import React from "react";

type ColSize = 
  | "1" 
  | "2" 
  | "3" 
  | "4" 
  | "5" 
  | "6" 
  | "7" 
  | "8" 
  | "9" 
  | "10" 
  | "11" 
  | "12";

  interface GridItemProps {
  xs?: ColSize;
  sm?: ColSize;
  md?: ColSize;
  lg?: ColSize;
  xl?: ColSize;
  children: React.ReactNode;
  props?: any;
  interfaceName?: string;
  className?: string;
  dataSource?: boolean;
}



export const GridItem: React.FC<GridItemProps> = ({ xs, sm, lg, md, xl, interfaceName, props = {}, children, dataSource = false, className = "" }) => {
  const gridParams = props?.params?.GridParameters || "";
  const styles = props?.params?.Styles || "";

  const colClasses = cn(
    xs ? `col-${xs}` : "col-12",
    sm ? `sm:col-${sm}` : "",
    md ? `md:col-${md}` : "",
    lg ? `lg:col-${lg}` : "",
    xl ? `xl:col-${xl}` : "",
  );
  

  return (
    <div className={twMerge("component flex-item", colClasses, interfaceName, gridParams, className, styles )}>
      {children}
    </div>
  )
}

export const Component: React.FC = () => {
  return (
      <GridItem xs="12" lg="2">
        <p>Hello World</h1>
      </GridItem>
  )
}

@mjbvz
Copy link
Contributor

mjbvz commented Mar 11, 2024

@jrieken I think this is generic suggest feature request to use alphanumeric sorting

@jrieken
Copy link
Member

jrieken commented Mar 12, 2024

This might be something with TS, using the snippet below I see that all entries have the same sort text

Screenshot 2024-03-12 at 08 32 12
type ColSize = 
  | "1" 
  | "2" 
  | "3" 
  | "4" 
  | "5" 
  | "6" 
  | "7" 
  | "8" 
  | "9" 
  | "10" 
  | "11" 
	| "12";
  
let foo: ColSize = 

@mjbvz
Copy link
Contributor

mjbvz commented Mar 12, 2024

@jrieken Ok thanks, will move upstream to get TS returning the items in the correct array order. That may be easier than changing the sortText

Example response today showing the wrong order:

024-03-12 08:54:39.719 [trace] <semantic> Response received: completionInfo (85). Request took 18 ms. Success: true  {
    "flags": 1,
    "isGlobalCompletion": true,
    "isMemberCompletion": false,
    "isNewIdentifierLocation": true,
    "entries": [
        {
            "name": "\"1\"",
            "kind": "string",
            "kindModifiers": "",
            "sortText": "11"
        },
        {
            "name": "\"10\"",
            "kind": "string",
            "kindModifiers": "",
            "sortText": "11"
        },
...

@mjbvz mjbvz transferred this issue from microsoft/vscode Mar 12, 2024
@mjbvz mjbvz changed the title Autocomplete Suggestions for Union Types are not in Order" Return completions in alphanumeric order Mar 12, 2024
@mjbvz mjbvz unassigned jrieken and mjbvz Mar 12, 2024
@RyanCavanaugh RyanCavanaugh added Not a Defect This behavior is one of several equally-correct options and removed Not a Defect This behavior is one of several equally-correct options labels Mar 12, 2024
@RyanCavanaugh
Copy link
Member

What's the bug here? The sortText isn't wrong; it's this entry:

    export const SortText = {
        // Presets
        LocalDeclarationPriority: "10" as SortText,
        LocationPriority: "11" as SortText,
        OptionalMember: "12" as SortText,

The items are coming back in lexical string ordering; VS Code can reorder those if that's desired

@jrieken
Copy link
Member

jrieken commented Mar 12, 2024

I think there are different understandings of sortText. For VS Code it means how an item is sorted relative to other items of a result. When all sortText-values are equal we fallback to comparing labels.

@RyanCavanaugh So the ask is that TS sorts its suggestion in lexical order (in this case) or in the order declaration (in this case) because TS is has the most complete knowledge

@RyanCavanaugh
Copy link
Member

It is sorted. 1 comes before 2 and it's a lexicographic sort.

@mjbvz
Copy link
Contributor

mjbvz commented Mar 12, 2024

Within the same sortText level, TS seem to already sort completion items. I think this uses TS's compareStringsCaseSensitiveUI

What we'd like is for this to use an alphanumeric sort. This may be as simple as adding numeric: true in the Intl.Collator used:

const comparer = new Intl.Collator(locale, { usage: "sort", sensitivity: "variant" }).compare;

RyanCavanaugh added a commit to RyanCavanaugh/TypeScript that referenced this issue Mar 12, 2024
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Experience Enhancement Noncontroversial enhancements labels Mar 12, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants