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

sortText of ItemCompletion are being ignored when comparing to ItemCompletion that doesn't specify the sortText field #66109

Closed
natanfudge opened this issue Jan 6, 2019 · 7 comments
Assignees
Labels
suggest IntelliSense, Auto Complete under-discussion Issue is under discussion for relevance, priority, approach

Comments

@natanfudge
Copy link

Issue Type: Bug

  • Create a new Typescript extension with yo code.

  • In package.json, replace the actionEvents field with

      "activationEvents": [
      	"*"
      ],
    
  • Replace extension.ts with the following code:

      import * as vscode from 'vscode';
    
    
      export function activate(context: vscode.ExtensionContext) {
    
      	let provider = vscode.languages.registerCompletionItemProvider("plaintext", {
      	provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext){
      		return [
      			{
      				label:"C",
      				detail:"Should show above the B",
      				sortText :"A"
      			},
      			{
      				label:"B",
      				detail:"Should show below the C",
    
      			}
      		]
      	}
      	});
    
      	context.subscriptions.push(provider);
      }
    
      export function deactivate() {}
    
  • Run the extension and create a new txt file.

  • Press ctrl+space to show completion options.

What I expected:

The 'C' option will be sorted to be shown above the 'B' option, because it has a sortText of 'A'.

What actually happened:

The 'C' option will be sorted to be shown below the 'B' option, because its sortText is being ignored and the label is used for sorting instead.

You can see that if you just add a sortText of 'B' to 'B' it works as expected.

{
	label:"C",
	detail:"Should show above the B",
	sortText :"A"
},
{
	label:"B",
	detail:"Should show below the C",
	sortText:"B"

}

VS Code version: Code - Insiders 1.31.0-insider (bae6c84, 2019-01-04T06:17:20.719Z)
OS version: Windows_NT x64 10.0.17134

System Info
Item Value
CPUs Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz (8 x 2394)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 15.91GB (10.39GB free)
Process Argv
Screen Reader no
VM 50%
Extensions: none
@jrieken jrieken added under-discussion Issue is under discussion for relevance, priority, approach suggest IntelliSense, Auto Complete labels Jan 7, 2019
@jrieken
Copy link
Member

jrieken commented Jan 7, 2019

The 'C' option will be sorted to be shown above the 'B' option, because it has a sortText of 'A'.

Hm, today we only compare sortText with another sortText and not with a fallback. We can consider filling sortText (and also filterText) with the label when unset but if remember correctly this was done for a reason (a few years back...) I can give it a try, it will certainly make the code easier.

@alshain
Copy link

alshain commented Apr 6, 2019

@jrieken Does that mean, that the documentation is currently outdated?

A string that should be used when comparing this item with other items. When falsy the label is used.

https://code.visualstudio.com/api/references/vscode-api#CompletionItem.sortText

@vivlimmsft
Copy link

Another way this can surface is if you have multiple extensions contributing to the same completion list, with one using sortText and another not.

IntelliCode uses sortText to bring our recommendations to the top of the list. If another extension is providing completion items which omit sortText, those can appear above the recommendations. This isn't a great experience since we are also applying editor.suggestSelection: first to focus that first item, which we expect to be a recommendation.

@jrieken did you end up trying what you mentioned above?

@jrieken
Copy link
Member

jrieken commented Sep 9, 2019

@jrieken did you end up trying what you mentioned above?

No, but we should. I will push a change today and then we (that includes your and IntelliCode) need to observe how https://code.visualstudio.com/insiders/ behaves.

@jrieken jrieken added this to the September 2019 milestone Sep 9, 2019
jrieken added a commit that referenced this issue Sep 9, 2019
@jrieken
Copy link
Member

jrieken commented Sep 13, 2019

@mjbvz Just a heads up that this changed - I believe the original (questionable) behaviour was introduced for TS, or TS as it was years back, and I wonder if you have observed any difference since the last week?

@vivlimmsft
Copy link

@jrieken Sorry for the delay, I just had a chance to try this and it looks good to me.

@jrieken
Copy link
Member

jrieken commented Sep 30, 2019

Yeah, we haven't seen issues (yet) and I am all in for shipping like this in September.

@jrieken jrieken closed this as completed Sep 30, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
suggest IntelliSense, Auto Complete under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

5 participants
@alshain @jrieken @natanfudge @vivlimmsft and others