question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Take Over mode][Suggestion] Add Setting to Force Suggestions Ordering

See original GitHub issue

Some Background

This is a continuation of https://github.com/johnsoncodehk/volar/issues/974#issuecomment-1047105363 and comment below.

You just said

We need to be consistent with VSCode, because their designed behavior is verified by more users, and changing it in volar might be counterproductive.

However the behavior is already inconsistent, e.g. Volar is already much bettter comparing to what we have with builtin TS extension right now. I also noticed that Volar loads much faster and overall has better performance.

I have a repo, where builtin TS extension gives false errors (suppose just crashes) on pnpm start until I restart the server and this is not a case with your Volar.

So I always recommend to everyone to disable builtin TS extension globally in favor of takeover mode.

Feature Request

By default vscode agressively sorts everything by label, so initial order of suggestions is lost.

I’m just asking you to add a volar.extended.forceSortSuggestions setting. Here https://github.com/johnsoncodehk/volar/blob/master/packages/server/src/features/languageFeatures.ts#L45 add

if (list) list.items.forEach((item, i) => {
    item.sortText = `${item.sortText ?? ''}${i}`
})

Here is a code you can test with:

interface Foo {
	b: string,
}

interface Bar {
	c: boolean,
}

interface Test extends Foo, Bar {
	a: number
}

const d: Test = {
// trigger suggestions here
};

The setting will be disabled by default, so we don’t break anything for existing users.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
zardoycommented, May 7, 2022

sorting is consistent to original response

I finally have had time to dig into it. If you’re curious why you had it: https://github.com/microsoft/TypeScript/issues/49012 (spoiler: we’ve had different versions of the TS Server somehow)

0reactions
zardoycommented, Apr 28, 2022

Sorry for late reply. @johnsoncodehk, just if you’re curious, I tried a simple TS plugin that solves the issue. It works well in all cases from above

import ts_module from 'typescript/lib/tsserverlibrary'

export = function ({ typescript }: { typescript: typeof ts_module }) {
    return {
        create(info: ts.server.PluginCreateInfo) {
            // Set up decorator object
            const proxy: ts.LanguageService = Object.create(null)

            for (const k of Object.keys(info.languageService)) {
                const x = info.languageService[k]!
                // @ts-expect-error - JS runtime trickery which is tricky to type tersely
                proxy[k] = (...args: Array<Record<string, unknown>>) => x.apply(info.languageService, args)
            }

            proxy.getCompletionsAtPosition = (fileName, position, options) => {
                const prior = info.languageService.getCompletionsAtPosition(fileName, position, options)
                if (!prior) return
                // Feature: Force Suggestion Sorting
                prior.entries = prior.entries.map((entry, index) => ({ ...entry, sortText: `${entry.sortText ?? ''}${index}` }))
                return prior
            }
            return proxy
        },
    }
}

Sorry I didn’t really have time to figure out why it doesn’t work with the latest versions of Volar. It does work with builtin TS support (4.6.3) and I hope there will be a way to use this simple plugin in Volar.

Again, I found it incredibly useful, so I think I will even publish this as extension. Will Volar read and use typescriptServerPlugins from ext?

Read more comments on GitHub >

github_iconTop Results From Across the Web

IntelliSense in Visual Studio Code
Sorting of suggestions depends on extension information and on how well they match the current word you are typing. In addition, you can...
Read more >
Code completion | WebStorm Documentation - JetBrains
To turn it on, go to the Editor | General | Code Completion page of the IDE settings Ctrl+Alt+S and select Suggest variable...
Read more >
Suggest changes - GitLab Docs
To start a batch of suggestions to apply with a single commit, select Add suggestion to batch: A code change suggestion displayed, with...
Read more >
Automatically fill in your information in Safari on iPhone
In the Safari app , use AutoFill to automatically fill in credit card information, contact information, and user names and passwords. Set up...
Read more >
Formatting Answer Choices - Qualtrics
If desired, select Reverse order to use choices in the reverse order, e.g., ... Show all: Select this option to add the suggested...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found