mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 17:19:01 +01:00
Add source code action kind
Fixes #47621 Adds the concept of a source code action that applies to an entire file. Does not show these actions in the lightbulb menu by default
This commit is contained in:
@@ -13,6 +13,10 @@ import { isSupportedLanguageMode } from '../utils/languageModeIds';
|
||||
import API from '../utils/api';
|
||||
import { Lazy } from '../utils/lazy';
|
||||
import TypeScriptServiceClientHost from '../typeScriptServiceClientHost';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
|
||||
export class OrganizeImportsCommand implements Command {
|
||||
public static readonly Ids = ['javascript.organizeImports', 'typescript.organizeImports'];
|
||||
@@ -84,3 +88,30 @@ export class OrganizeImportsContextManager {
|
||||
this.currentValue = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class OrganizeImportsCodeActionProvider implements vscode.CodeActionProvider {
|
||||
|
||||
public constructor(
|
||||
private readonly client: ITypeScriptServiceClient
|
||||
) { }
|
||||
|
||||
public provideCodeActions(
|
||||
document: vscode.TextDocument,
|
||||
_range: vscode.Range,
|
||||
_context: vscode.CodeActionContext,
|
||||
_token: vscode.CancellationToken
|
||||
): vscode.CodeAction[] {
|
||||
if (!isSupportedLanguageMode(document)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!this.client.apiVersion.has280Features()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const action = new vscode.CodeAction(localize('oraganizeImportsAction.title', "Organize Imports"), vscode.CodeActionKind.Source.append('organizeImports'));
|
||||
action.command = { title: '', command: OrganizeImportsCommand.Ids[0] };
|
||||
return [action];
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,7 @@ export default class LanguageProvider {
|
||||
this.disposables.push(languages.registerRenameProvider(selector, new (await import('./features/renameProvider')).default(client)));
|
||||
this.disposables.push(languages.registerCodeActionsProvider(selector, new (await import('./features/quickFixProvider')).default(client, this.formattingOptionsManager, commandManager, this.diagnosticsManager, this.bufferSyncSupport)));
|
||||
this.disposables.push(languages.registerCodeActionsProvider(selector, new (await import('./features/refactorProvider')).default(client, this.formattingOptionsManager, commandManager)));
|
||||
this.disposables.push(languages.registerCodeActionsProvider(selector, new (await import('./features/organizeImports')).OrganizeImportsCodeActionProvider(client)));
|
||||
|
||||
await this.initFoldingProvider();
|
||||
this.disposables.push(workspace.onDidChangeConfiguration(c => {
|
||||
|
||||
Reference in New Issue
Block a user