add code action: add a dependency (#634)
* add code action: add a dependency Signed-off-by: Yan Zhang <yanzh@microsoft.com> * fix tslint Signed-off-by: Yan Zhang <yanzh@microsoft.com>
This commit is contained in:
Родитель
3900799e34
Коммит
30948d2878
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as vscode from "vscode";
|
||||
import { ElementNode, getCurrentNode, XmlTagName } from "../utils/lexerUtils";
|
||||
|
||||
class CodeActionProvider implements vscode.CodeActionProvider {
|
||||
public provideCodeActions(document: vscode.TextDocument, range: vscode.Range | vscode.Selection, _context: vscode.CodeActionContext, _token: vscode.CancellationToken): vscode.Command[] | undefined {
|
||||
const documentText: string = document.getText();
|
||||
const cursorOffset: number = document.offsetAt(range.start);
|
||||
const currentNode: ElementNode | undefined = getCurrentNode(documentText, cursorOffset);
|
||||
if (currentNode === undefined || currentNode.contentStart === undefined || currentNode.contentEnd === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (currentNode.tag === XmlTagName.Dependencies) {
|
||||
const addDependencyCommand: vscode.Command = {
|
||||
command: "maven.project.addDependency",
|
||||
title: "Add a dependency from Maven Central Repository...",
|
||||
arguments: [{
|
||||
pomPath: document.uri.fsPath
|
||||
}]
|
||||
};
|
||||
return [addDependencyCommand];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const codeActionProvider: CodeActionProvider = new CodeActionProvider();
|
|
@ -8,6 +8,7 @@ import * as vscode from "vscode";
|
|||
import { Progress, Uri } from "vscode";
|
||||
import { dispose as disposeTelemetryWrapper, initialize, instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
|
||||
import { ArchetypeModule } from "./archetype/ArchetypeModule";
|
||||
import { codeActionProvider } from "./codeAction/codeActionProvider";
|
||||
import { completionProvider } from "./completion/completionProvider";
|
||||
import { definitionProvider } from "./definition/definitionProvider";
|
||||
import { initExpService } from "./experimentationService";
|
||||
|
@ -189,6 +190,8 @@ function registerPomFileAuthoringHelpers(context: vscode.ExtensionContext): void
|
|||
context.subscriptions.push(vscode.languages.registerDefinitionProvider([...pomSelector, {
|
||||
pattern: "**/*.pom"
|
||||
}], definitionProvider));
|
||||
// add a dependency
|
||||
context.subscriptions.push(vscode.languages.registerCodeActionsProvider(pomSelector, codeActionProvider));
|
||||
}
|
||||
|
||||
async function mavenHistoryHandler(item: MavenProject | undefined): Promise<void> {
|
||||
|
|
Загрузка…
Ссылка в новой задаче