Skip to content

Commit 3bb254c

Browse files
authored
feat: add toggles for organize imports and symbols (#1350)
1 parent 4542e0a commit 3bb254c

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ extension has the following configuration options:
206206
by the Deno Language Server to host its TS server.
207207
- `deno.lint`: Controls if linting information will be provided by the Deno
208208
Language Server. _boolean, default `true`_
209+
- `deno.organizeImports.enabled`: Controls if the Deno language server
210+
contributes organize imports code actions. Disable to rely on VS Code's
211+
built-in TypeScript/JavaScript organizer. _boolean, default `true`_
212+
- `deno.symbols.document.enabled`: Controls if the Deno language server
213+
contributes document symbols. Disable to rely on VS Code's built-in provider.
214+
_boolean, default `true`_
215+
- `deno.symbols.workspace.enabled`: Controls if the Deno language server
216+
contributes workspace symbols. Disable to rely on VS Code's built-in
217+
provider. _boolean, default `true`_
209218
- `deno.maxTsServerMemory`: Maximum amount of memory the TypeScript isolate can
210219
use. Defaults to 3072 (3GB).
211220
- `deno.suggest.imports.hosts`: A map of domain hosts (origins) that are used

client/src/commands.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ export function startLanguageServer(
168168
}
169169
env["DENO_V8_FLAGS"] = getV8Flags();
170170

171+
const isProvideSettingEnabled = (
172+
setting: string,
173+
resource?: vscode.Uri,
174+
) =>
175+
vscode.workspace.getConfiguration(EXTENSION_NS, resource).get<boolean>(
176+
setting,
177+
) ?? true;
178+
171179
const shell = process.platform === "win32" &&
172180
/\.([Cc][Mm][Dd]|[Bb][Aa][Tt])$/.test(command);
173181
const serverOptions: ServerOptions = {
@@ -203,6 +211,37 @@ export function startLanguageServer(
203211
return response;
204212
},
205213
},
214+
provideCodeActions: async (
215+
document,
216+
range,
217+
context,
218+
token,
219+
next,
220+
) => {
221+
const actions = await next(document, range, context, token);
222+
if (
223+
actions == null || !Array.isArray(actions) ||
224+
isProvideSettingEnabled("organizeImports.enabled", document.uri)
225+
) {
226+
return actions;
227+
}
228+
return actions.filter((action) => {
229+
const kind = (action as vscode.CodeAction).kind;
230+
return !kind?.contains(vscode.CodeActionKind.SourceOrganizeImports);
231+
});
232+
},
233+
provideDocumentSymbols: (document, token, next) => {
234+
if (!isProvideSettingEnabled("symbols.document.enabled", document.uri)) {
235+
return [];
236+
}
237+
return next(document, token);
238+
},
239+
provideWorkspaceSymbols: (query, token, next) => {
240+
if (!isProvideSettingEnabled("symbols.workspace.enabled")) {
241+
return [];
242+
}
243+
return next(query, token);
244+
},
206245
},
207246
...extensionContext.clientOptions,
208247
},

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,36 @@
557557
false
558558
]
559559
},
560+
"deno.organizeImports.enabled": {
561+
"type": "boolean",
562+
"default": true,
563+
"markdownDescription": "Controls if the Deno language server contributes organize imports code actions. Disable to rely on VS Code's built-in TypeScript/JavaScript organize imports instead.",
564+
"scope": "resource",
565+
"examples": [
566+
true,
567+
false
568+
]
569+
},
570+
"deno.symbols.document.enabled": {
571+
"type": "boolean",
572+
"default": true,
573+
"markdownDescription": "Controls if the Deno language server provides document symbols. Disable to rely on VS Code's built-in providers instead.",
574+
"scope": "resource",
575+
"examples": [
576+
true,
577+
false
578+
]
579+
},
580+
"deno.symbols.workspace.enabled": {
581+
"type": "boolean",
582+
"default": true,
583+
"markdownDescription": "Controls if the Deno language server provides workspace symbols. Disable to rely on VS Code's built-in providers instead.",
584+
"scope": "resource",
585+
"examples": [
586+
true,
587+
false
588+
]
589+
},
560590
"deno.internalDebug": {
561591
"type": "boolean",
562592
"default": false,

0 commit comments

Comments
 (0)