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

Create available commands for IDEs other than VSCode #38

Open
johnsoncodehk opened this issue May 6, 2023 · 3 comments
Open

Create available commands for IDEs other than VSCode #38

johnsoncodehk opened this issue May 6, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@johnsoncodehk
Copy link
Member

Currently we have factory code for building commands in the following code, but it only works for VSCode (seems to work for coc too). We should judge the IDE of the language client to return the command format actually supported by the current IDE.

commands: {
rename: {
create(uri, position) {
const source = toSourceLocation(uri, position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename);
if (!source) {
return;
}
return vscode.Command.create(
'',
'editor.action.rename',
source.uri,
source.position,
);
},
is(command) {
return command.command === 'editor.action.rename';
},
},
showReferences: {
create(uri, position, locations) {
const source = toSourceLocation(uri, position);
if (!source) {
return;
}
const sourceReferences: vscode.Location[] = [];
for (const reference of locations) {
if (context.documents.isVirtualFileUri(reference.uri)) {
for (const [_, map] of context.documents.getMapsByVirtualFileUri(reference.uri)) {
const range = map.toSourceRange(reference.range);
if (range) {
sourceReferences.push({ uri: map.sourceFileDocument.uri, range });
}
}
}
else {
sourceReferences.push(reference);
}
}
return vscode.Command.create(
locations.length === 1 ? '1 reference' : `${locations.length} references`,
'editor.action.showReferences',
source.uri,
source.position,
sourceReferences,
);
},
is(command) {
return command.command === 'editor.action.showReferences';
},
},
setSelection: {
create(position: vscode.Position) {
return vscode.Command.create(
'',
'setSelection',
{
selection: {
selectionStartLineNumber: position.line + 1,
positionLineNumber: position.line + 1,
selectionStartColumn: position.character + 1,
positionColumn: position.character + 1,
},
},
);
},
is(command) {
return command.command === 'setSelection';
}
},

@johnsoncodehk johnsoncodehk added the enhancement New feature or request label May 6, 2023
@rchl
Copy link

rchl commented May 6, 2023

In ST I don't think we have anything currently. We could either support the editor.action.rename command globally to be interoperable with VSCode or handle it with some custom code in LSP-volar.

@johnsoncodehk
Copy link
Member Author

Thank you for the information. If ST does not support it for now, it should at least return undefined to avoid ST errors.

@rchl
Copy link

rchl commented May 17, 2023

Do you have any specific examples where editor.action.showReferences is triggered and actually works? Because I found some cases where it is triggered but in those cases TS says that the location doesn't support rename. You can read more details in sublimelsp/LSP#2249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants