-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
[Take Over mode][Suggestion] Add Setting to Force Suggestions Ordering #1005
Comments
I don't really suggest that, at least that's not the purpose of volar. 😅 Do you expected Do you have other example or reference issue for the problem? [
{
name: 'a',
kind: 'property',
kindModifiers: '',
sortText: '11',
source: undefined,
hasAction: undefined,
isRecommended: undefined,
insertText: undefined,
replacementSpan: undefined,
sourceDisplay: undefined,
isSnippet: undefined,
isPackageJsonImport: undefined,
isImportStatementCompletion: undefined,
data: undefined
},
{
name: 'b',
kind: 'property',
kindModifiers: '',
sortText: '11',
source: undefined,
hasAction: undefined,
isRecommended: undefined,
insertText: undefined,
replacementSpan: undefined,
sourceDisplay: undefined,
isSnippet: undefined,
isPackageJsonImport: undefined,
isImportStatementCompletion: undefined,
data: undefined
},
{
name: 'c',
kind: 'property',
kindModifiers: '',
sortText: '11',
source: undefined,
hasAction: undefined,
isRecommended: undefined,
insertText: undefined,
replacementSpan: undefined,
sourceDisplay: undefined,
isSnippet: undefined,
isPackageJsonImport: undefined,
isImportStatementCompletion: undefined,
data: undefined
}
] |
Interesting... But I definitely see the deffirence with With the change from first comment: This is something that WebStorm does by default. However WebStorm shows correct order of suggestions only when some time passes after IDE load. Another example would be I don't really know how to print the item list from https://github.com/johnsoncodehk/volar/blob/master/packages/server/src/features/languageFeatures.ts#L45. How did you check that? I tried placing breakpoint in several places, but they didn't work. Anyway, can you install |
@zardoy seems the sorting is consistent to original response. pinia: @reduxjs/toolkit: |
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 |
I finally have had time to dig into it. If you're curious why you had it: microsoft/TypeScript#49012 (spoiler: we've had different versions of the TS Server somehow) |
I thought about it for a long time, I think vueserver should not support tsserver plugin. The tsserver plugin relies on the tsserver context, and if we try to support it, vueserver will couple the tsserver specification. As an alternative volar plugin is sufficient for your use case, you can implement it with the following code in volar.config.js. module.exports = {
plugins: [
/**
* @type {import('@volar/language-service').LanguageServicePlugin}
*/
(context) => {
if (context.typescript) {
const getCompletionsAtPosition = context.typescript.languageService.getCompletionsAtPosition;
context.typescript.languageService.getCompletionsAtPosition = (fileName, position, options) => {
const result = getCompletionsAtPosition(fileName, position, options);
if (result) {
result.entries = result.entries.sort(/* ... */);
}
return result;
};
}
return {};
},
],
}; |
@johnsoncodehk can I put it into VSCode extension? I obviously want to use this in every project, putting and keeping up to date this config file in ~30 project isn't a way for me 😂. If volar doesn't support looking for this configuration from contributes point of extensions, I think it would be easy to implement (though there should be a way to read VSCode configuration then). Also, as I understand from your code, you are overriding methods of language service and this is exactly what TS plugin does. So what's the difference then? |
You can put it to a single folder like /volar-global/config.js, and add There is no difference between this use case and the ts plugin, because this use case does not rely on more ts plugin contexts like serverHost, projectHost. So you can try to apply your ts plugin directly in the volar plugin. |
We have the same problem with vue-tsc, where the plugins "typescript-plugin-css-modules" are not used by vue-tsc. Is this the same resolution? |
@MichaelBitard TS plugin is only applicable to tsserver, it is not valid for tsc or vue-tsc TS plugin. tsc has workarounds like ttypescript, but that's out of volar's project scope. If you want to change vue-tsc type behavior, you can try |
Thanks, I did not knew that! Indeed it is in typescript documentation, plugins are for augmenting the editing experience, not for changing the compilation behavior. |
So in fact compilerOptions.plugins is wrong in meaning. 😅 |
Yeap, that's confusing 💯 |
@johnsoncodehk I actually tested it almost instantly, but completely forgot to reply here. So following what you said I successfully applied whole plugin to Volar and all features work well!
But how should I've done this? Currently I'm changing user setting Also, how its possible with
But why? Why don't provide some early support for ts plugins for example in already existing {
"contributes": {
"typescriptServerPlugins": [
{
"name": "typescript-essential-plugins",
"enableForWorkspaceTypeScriptVersions": true,
"volarCompatibilityVersion": 1
}
]
}
} I don't mind if it gets thrown away over time, its still better than nothing. If its just matter of time and focus just let me know I'll try to provide my own implentation. |
First thanks for the feedback. The advice is just for users and not for extension authors, so Contribution points is the appropriate approach, and the reasons for avoiding it in the past are:
If we're going to support Contribution Points, I hope at least volarjs.github.io has documentation for Contribution Points and the Plugin API, so it will not be something users can't address. For the second question, have you tried passing in the uri as the second parameter? e.g. |
Thank you so much for quick replly!
With all that said, it can create confusion for users but not for TS dev (I'm using it to improve editing experience only) and as you can probably see I don't really use Volar plugin API (just patching TS LS methods), and even if API isnt stable yet, I'd happy to update support (I'm already using volar.config.js anyway). I just creates confusion for me why contribution point can't be supported when loading plugin from user setting is already supported? Anyway I'm eagarly waiting for it to be implemented, so I can stop using setting workaround. So let know when some kind of contribution point will be available (or when you have plans for it)!
At very least we can add contribution point to json schema so it will be more visible for vscode developers.
Thanks, but I resolved it. FYI I looked at GH code, and looks like the right way to do this: |
@johnsoncodehk By the way I'm trying to change results of references result from volar.config.ts (currently overriding typescript ls method), but it seems to me that I don't see any documentation on existing language service plugins (only https://github.com/vuejs/language-tools/tree/master/packages/vue-language-service/src/plugins), and I'm trying this: // plugin in volar.config.js
return {
findReferences() {
return []
},
} But I'm still getting results, so as I understand plugins can only append results, but not change other results? So can I use something like middlewares? |
It uses
Yes, you're right. We don't have middleware API for now (v1.0.24). |
Some Background
This is a continuation of #974 (comment) and comment below.
You just said
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 addHere is a code you can test with:
The setting will be disabled by default, so we don't break anything for existing users.
The text was updated successfully, but these errors were encountered: