diff --git a/src/language/LanguageExtensions.ts b/src/language/LanguageExtensions.ts index ebb7a55..fcdeddd 100644 --- a/src/language/LanguageExtensions.ts +++ b/src/language/LanguageExtensions.ts @@ -3,7 +3,7 @@ import { NugetVersionCodeActionProvider } from "./actions/NugetVersionCodeAction import { NugetNameCompletionItemProvider } from "./completions/NugetNameCompletionItemProvider"; import { NugetVersionCompletionItemProvider } from "./completions/NugetVersionCompletionItemProvider"; import { CodeDecoratorController } from "./decorators/CodeDecoratorController"; -import { CSPROJ } from "./filters"; +import { CSPROJ, PACKAGES_PROPS } from "./filters"; import { NugetVersionDecorator } from "./decorators/NugetVersionDecorator"; export class LanguageExtensions { @@ -12,27 +12,34 @@ export class LanguageExtensions { } register() { - const decorator = new CodeDecoratorController(this.context, [ - new NugetVersionDecorator() - ]); + const fileTypes = [ + { filter: CSPROJ, tagName: "PackageReference"}, + { filter: PACKAGES_PROPS, tagName: "PackageVersion"} + ]; + + const decorator = new CodeDecoratorController(this.context, + fileTypes.map(({filter, tagName}) => new NugetVersionDecorator(filter, tagName)) + ); decorator.register(); - this.context.subscriptions.push(vscode.languages.registerCodeActionsProvider( - CSPROJ, - new NugetVersionCodeActionProvider(), - )); - - this.context.subscriptions.push(vscode.languages.registerCompletionItemProvider( - CSPROJ, - new NugetNameCompletionItemProvider(), - '.', '"' - )); - - this.context.subscriptions.push(vscode.languages.registerCompletionItemProvider( - CSPROJ, - new NugetVersionCompletionItemProvider(), - '.', '"' - )); + fileTypes.forEach(({filter, tagName}) => { + this.context.subscriptions.push(vscode.languages.registerCodeActionsProvider( + filter, + new NugetVersionCodeActionProvider(tagName), + )); + + this.context.subscriptions.push(vscode.languages.registerCompletionItemProvider( + filter, + new NugetNameCompletionItemProvider(tagName), + '.', '"' + )); + + this.context.subscriptions.push(vscode.languages.registerCompletionItemProvider( + filter, + new NugetVersionCompletionItemProvider(tagName), + '.', '"' + )); + }); } } diff --git a/src/language/actions/NugetVersionCodeActionProvider.ts b/src/language/actions/NugetVersionCodeActionProvider.ts index 4d7420f..0e99a1a 100644 --- a/src/language/actions/NugetVersionCodeActionProvider.ts +++ b/src/language/actions/NugetVersionCodeActionProvider.ts @@ -2,10 +2,15 @@ import * as vscode from "vscode"; import * as nuget from '@extensions/nuget'; export class NugetVersionCodeActionProvider implements vscode.CodeActionProvider { + private readonly regEx: RegExp; + + constructor(tagName: string) { + this.regEx = new RegExp(`<${tagName} Include="(.*)" Version="(.*)"`); + } + async provideCodeActions(document: vscode.TextDocument, range: vscode.Range | vscode.Selection, context: vscode.CodeActionContext, token: vscode.CancellationToken): Promise<(vscode.CodeAction | vscode.Command)[] | null | undefined> { const line = document.lineAt(range.start.line).text; - const regEx = / | null | undefined> { const linePrefix = document.lineAt(position).text.substr(0, position.character); - const regEx = / | null | undefined> { const linePrefix = document.lineAt(position).text.substr(0, position.character); - const regEx = / { const text = editor.document.getText(); const okDecorations: vscode.DecorationOptions[] = []; const newDecorations: vscode.DecorationOptions[] = []; - const regEx = /