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

[monaco] properly register CodeActionProviders. #6556

Merged
merged 1 commit into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/monaco/src/browser/monaco-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function loadMonaco(vsRequire: any): Promise<void> {
'vs/platform/configuration/common/configurationModels',
'vs/editor/browser/services/codeEditorService',
'vs/editor/browser/services/codeEditorServiceImpl',
'vs/platform/markers/common/markerService',
'vs/platform/contextkey/common/contextkey',
'vs/platform/contextkey/browser/contextKeyService',
'vs/base/common/errors'
Expand All @@ -78,13 +79,15 @@ export function loadMonaco(vsRequire: any): Promise<void> {
filters: any, styler: any, platform: any, modes: any, suggest: any, snippetParser: any,
configuration: any, configurationModels: any,
codeEditorService: any, codeEditorServiceImpl: any,
markerService: any,
contextKey: any, contextKeyService: any,
error: any) => {
const global: any = self;
global.monaco.commands = commands;
global.monaco.actions = actions;
global.monaco.keybindings = Object.assign({}, keybindingsRegistry, keybindingResolver, resolvedKeybinding, keybindingLabels, keyCodes);
global.monaco.services = Object.assign({}, simpleServices, standaloneServices, configuration, configurationModels, codeEditorService, codeEditorServiceImpl);
global.monaco.services = Object.assign({}, simpleServices, standaloneServices, configuration, configurationModels,
codeEditorService, codeEditorServiceImpl, markerService);
global.monaco.quickOpen = Object.assign({}, quickOpenWidget, quickOpenModel);
global.monaco.filters = filters;
global.monaco.theme = styler;
Expand Down
7 changes: 7 additions & 0 deletions packages/monaco/src/typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ declare module monaco.services {
set<T>(id: any, instanceOrDescriptor: T): T;
}

export interface IMarkerService {
read(filter?: { owner?: string; resource?: monaco.Uri; severities?: number, take?: number; }): editor.IMarkerData[];
}

export module StaticServices {
export function init(overrides: monaco.editor.IEditorOverrideServices): [ServiceCollection, monaco.instantiation.IInstantiationService];
export const standaloneThemeService: LazyStaticService<IStandaloneThemeService>;
Expand All @@ -520,6 +524,7 @@ declare module monaco.services {
export const configurationService: LazyStaticService<IConfigurationService>;
export const resourcePropertiesService: LazyStaticService<ITextResourcePropertiesService>;
export const instantiationService: LazyStaticService<monaco.instantiation.IInstantiationService>;
export const markerService: LazyStaticService<IMarkerService>;
}
}

Expand Down Expand Up @@ -844,6 +849,8 @@ declare module monaco.modes {
export const DocumentSymbolProviderRegistry: LanguageFeatureRegistry<monaco.languages.DocumentSymbolProvider>;

export const CompletionProviderRegistry: LanguageFeatureRegistry<monaco.languages.CompletionItemProvider>;

export const CodeActionProviderRegistry: LanguageFeatureRegistry<monaco.languages.CodeActionProvider & { providedCodeActionKinds?: string[] }>;
}

declare module monaco.suggest {
Expand Down
19 changes: 10 additions & 9 deletions packages/plugin-ext/src/main/browser/languages-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,21 +656,22 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}, token);
}

$registerQuickFixProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], codeActionKinds?: string[]): void {
$registerQuickFixProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], providedCodeActionKinds?: string[]): void {
const languageSelector = fromLanguageSelector(selector);
const quickFixProvider = this.createQuickFixProvider(handle, codeActionKinds);
this.register(handle, monaco.languages.registerCodeActionProvider(languageSelector, quickFixProvider));
}

protected createQuickFixProvider(handle: number, providedCodeActionKinds?: string[]): monaco.languages.CodeActionProvider {
return {
provideCodeActions: async (model, rangeOrSelection, monacoContext, token) => this.provideCodeActions(handle, model, rangeOrSelection, monacoContext, token)
const quickFixProvider = {
provideCodeActions: (model: monaco.editor.ITextModel, range: monaco.Range,
context: monaco.languages.CodeActionContext, token: monaco.CancellationToken): monaco.languages.CodeActionList | Promise<monaco.languages.CodeActionList> => {
const markers = monaco.services.StaticServices.markerService.get().read({ resource: model.uri }).filter(m => monaco.Range.areIntersectingOrTouching(m, range));
return this.provideCodeActions(handle, model, range, { markers, only: context.only }, token);
},
providedCodeActionKinds
};
this.register(handle, monaco.modes.CodeActionProviderRegistry.register(languageSelector, quickFixProvider));
}

protected async provideCodeActions(handle: number, model: monaco.editor.ITextModel,
rangeOrSelection: Range, context: monaco.languages.CodeActionContext,
token: monaco.CancellationToken): Promise<monaco.languages.CodeActionList | Promise<monaco.languages.CodeActionList>> {
token: monaco.CancellationToken): Promise<monaco.languages.CodeActionList | monaco.languages.CodeActionList> {
const actions = await this.proxy.$provideCodeActions(handle, model.uri, rangeOrSelection, context, token);
if (!actions) {
return undefined!;
Expand Down