Provide trigger and documentation to monaco code action provider (#149937)

* Provide trigger to monaco code action provider

* Provide documentation to monaco code action provider

* Use an interface instead of a type
This commit is contained in:
Loïc Mangeonjean 2022-07-25 12:45:12 +02:00 committed by GitHub
parent f983ebca22
commit db1f5a2d02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 7 deletions

View file

@ -669,9 +669,6 @@ export interface CodeAction {
disabled?: string;
}
/**
* @internal
*/
export const enum CodeActionTriggerType {
Invoke = 1,
Auto = 2,
@ -1132,7 +1129,11 @@ export interface DocumentSymbolProvider {
provideDocumentSymbols(model: model.ITextModel, token: CancellationToken): ProviderResult<DocumentSymbol[]>;
}
export type TextEdit = { range: IRange; text: string; eol?: model.EndOfLineSequence };
export interface TextEdit {
range: IRange;
text: string;
eol?: model.EndOfLineSequence;
}
/**
* Interface used to format a model

View file

@ -15,6 +15,11 @@ export enum AccessibilitySupport {
Enabled = 2
}
export enum CodeActionTriggerType {
Invoke = 1,
Auto = 2
}
export enum CompletionItemInsertTextRule {
/**
* Adjust whitespace/indentation of multiline insert texts to

View file

@ -526,12 +526,13 @@ export function registerCodeActionProvider(languageSelector: LanguageSelector, p
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService);
return languageFeaturesService.codeActionProvider.register(languageSelector, {
providedCodeActionKinds: metadata?.providedCodeActionKinds,
documentation: metadata?.documentation,
provideCodeActions: (model: model.ITextModel, range: Range, context: languages.CodeActionContext, token: CancellationToken): languages.ProviderResult<languages.CodeActionList> => {
const markerService = StandaloneServices.get(IMarkerService);
const markers = markerService.read({ resource: model.uri }).filter(m => {
return Range.areIntersectingOrTouching(m, range);
});
return provider.provideCodeActions(model, range, { markers, only: context.only }, token);
return provider.provideCodeActions(model, range, { markers, only: context.only, trigger: context.trigger }, token);
},
resolveCodeAction: provider.resolveCodeAction
});
@ -664,6 +665,11 @@ export interface CodeActionContext {
* Requested kind of actions to return.
*/
readonly only?: string;
/**
* The reason why code actions were requested.
*/
readonly trigger: languages.CodeActionTriggerType;
}
/**
@ -697,6 +703,8 @@ export interface CodeActionProviderMetadata {
* such as `["quickfix.removeLine", "source.fixAll" ...]`.
*/
readonly providedCodeActionKinds?: readonly string[];
readonly documentation?: ReadonlyArray<{ readonly kind: string; readonly command: languages.Command }>;
}
/**
@ -753,6 +761,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
SignatureHelpTriggerKind: standaloneEnums.SignatureHelpTriggerKind,
InlayHintKind: standaloneEnums.InlayHintKind,
InlineCompletionTriggerKind: standaloneEnums.InlineCompletionTriggerKind,
CodeActionTriggerType: standaloneEnums.CodeActionTriggerType,
// classes
FoldingRangeKind: languages.FoldingRangeKind,

17
src/vs/monaco.d.ts vendored
View file

@ -5848,6 +5848,10 @@ declare namespace monaco.languages {
* Requested kind of actions to return.
*/
readonly only?: string;
/**
* The reason why code actions were requested.
*/
readonly trigger: CodeActionTriggerType;
}
/**
@ -5878,6 +5882,10 @@ declare namespace monaco.languages {
* such as `["quickfix.removeLine", "source.fixAll" ...]`.
*/
readonly providedCodeActionKinds?: readonly string[];
readonly documentation?: ReadonlyArray<{
readonly kind: string;
readonly command: Command;
}>;
}
/**
@ -6450,6 +6458,11 @@ declare namespace monaco.languages {
disabled?: string;
}
export enum CodeActionTriggerType {
Invoke = 1,
Auto = 2
}
export interface CodeActionList extends IDisposable {
readonly actions: ReadonlyArray<CodeAction>;
}
@ -6786,11 +6799,11 @@ declare namespace monaco.languages {
provideDocumentSymbols(model: editor.ITextModel, token: CancellationToken): ProviderResult<DocumentSymbol[]>;
}
export type TextEdit = {
export interface TextEdit {
range: IRange;
text: string;
eol?: editor.EndOfLineSequence;
};
}
/**
* Interface used to format a model