Skip to content

Commit

Permalink
Documentation example
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Mar 17, 2020
1 parent 8e2f080 commit e4b0a50
Show file tree
Hide file tree
Showing 2 changed files with 1,912 additions and 3 deletions.
15 changes: 12 additions & 3 deletions code-actions-sample/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ const COMMAND = 'code-actions-sample.command';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.languages.registerCodeActionsProvider('markdown', new Emojizer(), {
providedCodeActionKinds: Emojizer.providedCodeActionKinds
providedCodeActionKinds: Emojizer.providedCodeActionKinds,
documentation: [
{
kind: vscode.CodeActionKind.Refactor, command: {
title: 'Docs',
command: 'do.the.bla'
}
}
]
}));

const emojiDiagnostics = vscode.languages.createDiagnosticCollection("emoji");
Expand All @@ -35,7 +43,8 @@ export function activate(context: vscode.ExtensionContext) {
export class Emojizer implements vscode.CodeActionProvider {

public static readonly providedCodeActionKinds = [
vscode.CodeActionKind.QuickFix
vscode.CodeActionKind.QuickFix,
vscode.CodeActionKind.Refactor,
];

public provideCodeActions(document: vscode.TextDocument, range: vscode.Range): vscode.CodeAction[] | undefined {
Expand Down Expand Up @@ -69,7 +78,7 @@ export class Emojizer implements vscode.CodeActionProvider {
}

private createFix(document: vscode.TextDocument, range: vscode.Range, emoji: string): vscode.CodeAction {
const fix = new vscode.CodeAction(`Convert to ${emoji}`, vscode.CodeActionKind.QuickFix);
const fix = new vscode.CodeAction(`Convert to ${emoji}`, vscode.CodeActionKind.Refactor);
fix.edit = new vscode.WorkspaceEdit();
fix.edit.replace(document.uri, new vscode.Range(range.start, range.start.translate(0, 2)), emoji);
return fix;
Expand Down
Loading

0 comments on commit e4b0a50

Please sign in to comment.