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

CodeAction and CodeActionProviderMetaData fields added #10073

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ export interface CodeAction {
edit?: WorkspaceEdit;
diagnostics?: MarkerData[];
kind?: string;
disabled?: { reason: string };
isPreferred?: boolean;
}

export interface CodeActionContext {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/main/browser/languages-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ function toMonacoAction(action: CodeAction): monaco.languages.CodeAction {
return {
...action,
diagnostics: action.diagnostics ? action.diagnostics.map(m => toMonacoMarkerData(m)) : undefined,
disabled: action.disabled?.reason,
edit: action.edit ? toMonacoWorkspaceEdit(action.edit) : undefined
};
}
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-ext/src/plugin/languages/code-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export class CodeActionAdapter {
command: this.commands.converter.toSafeCommand(candidate.command, toDispose),
diagnostics: candidate.diagnostics && candidate.diagnostics.map(Converter.convertDiagnosticToMarkerData),
edit: candidate.edit && Converter.fromWorkspaceEdit(candidate.edit),
kind: candidate.kind && candidate.kind.value
kind: candidate.kind && candidate.kind.value,
disabled: candidate.disabled,
isPreferred: candidate.isPreferred
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,10 @@ export class CodeAction {

kind?: CodeActionKind;

disabled?: { reason: string };

isPreferred?: boolean;

constructor(title: string, kind?: CodeActionKind) {
this.title = title;
this.kind = kind;
Expand Down
17 changes: 17 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7522,6 +7522,16 @@ declare module '@theia/plugin' {
*/
kind?: CodeActionKind;

/**
* Marks that the code action cannot currently be applied.
*/
disabled?: { reason: string };

/**
* Marks this as a preferred action.
*/
isPreferred?: boolean;

/**
* Creates a new code action.
*
Expand Down Expand Up @@ -7571,6 +7581,13 @@ declare module '@theia/plugin' {
* may list our every specific kind they provide, such as `CodeActionKind.Refactor.Extract.append('function`)`
*/
readonly providedCodeActionKinds?: ReadonlyArray<CodeActionKind>;

/**
* Documentation from the provider is shown in the code actions menu
*
* At most one documentation entry will be shown per provider.
*/
documentation?: ReadonlyArray<{ command: Command, kind: CodeActionKind }>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how the documentation field is transferred to the main side and ultimately the monaco editor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can omit support for documentation for now, it is used when registering registerCodeActionsProvider but our implementation differs from vscode in many ways:

registerCodeActionsProvider(
selector: theia.DocumentSelector,
provider: theia.CodeActionProvider,
pluginModel: PluginModel,
pluginInfo: PluginInfo,
metadata?: theia.CodeActionProviderMetadata
): theia.Disposable {
const callId = this.addNewAdapter(new CodeActionAdapter(provider, this.documents, this.diagnostics, pluginModel ? pluginModel.id : '', this.commands));
this.proxy.$registerQuickFixProvider(
callId,
pluginInfo,
this.transformDocumentSelector(selector),
metadata && metadata.providedCodeActionKinds ? metadata.providedCodeActionKinds.map(kind => kind.value!) : undefined
);
return this.createDisposable(callId);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But ultimately, we're registering the code action provider to the editor, which does have a documentation field. We should pass this info to the editor in Theia, as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsmaeder Would you know how to properly pass the documentation field? I myself am not sure how to go about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our definition of modes.CodeActionProvider is way out of date. We need to update our definition in monaco.d.ts and pass the necessary information to the front end through "registerQuickFixProvider". The current definition in monaco actually looks like this: https://github.com/microsoft/vscode/blob/2586299c42490a8ed6dff96ed731d44fcbe5b20e/src/vs/editor/common/languages.ts#L777

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looks like in the branch we currently use (0.23) of vs code, the definition lives here: (https://github.com/microsoft/vscode/blob/b882940dc6d5b2acb096969b9e43385248719df7/src/vs/editor/common/modes.ts#L740).

I believe it would work to extend the definition of CodeActionProvider in monaco.d.ts with the needed bits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Archie27376 : Please have a look at the hints that Thomas provided and let us know if you need further information!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonasHelming Dante's (@Archie27376) internship has terminated, someone else would need to pick up the pull-request.

}

/**
Expand Down