如何构造多个完成提供程序

时间:2019-03-17 07:15:17

标签: typescript visual-studio-code vscode-extensions

我正在编写扩展程序以提供网络扩展名api的扩展名。现在的问题是,我必须像一百万个注册完成提供商一样注册,它们会在不同的场合触发,例如有些会在chrome.上触发,有些会在chrome.tabs.上触发,有些会在chrome.tabs.onUpdated.上触发,依此类推。 。我刚开始编写VS Code扩展,并且我知道注册提供程序的方式是使用activate的{​​{1}}方法,现在看起来像这样。

extension.ts

我将所有不同的提供程序放在单独的文件中,并以import * as vscode from 'vscode'; import chromeCompletionItemProvider from './chrome/chromeCompletionItemProvider'; import tabsCompletionItemProvider from './chrome/tabs/tabsCompletionItemProvider'; import accessibilityFeaturesCompletionItemProvider from './chrome/accessibilityFeatures/accessibilityFeaturesCompletionItemProvider'; const documentSelector = ['javascript', 'typescript', 'plaintext']; export function activate(context: vscode.ExtensionContext) { let chromeProvider = vscode.languages.registerCompletionItemProvider(documentSelector, { provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) { const commitCharacterCompletion = new vscode.CompletionItem('chrome'); commitCharacterCompletion.commitCharacters = ['.']; commitCharacterCompletion.documentation = new vscode.MarkdownString('Chrome provides extensions with many special-purpose APIs like `chrome.runtime` and `chrome.alarms`.'); // return all completion items as array return [ commitCharacterCompletion, ]; } }); const chromeItemsProvider = vscode.languages.registerCompletionItemProvider(documentSelector, chromeCompletionItemProvider, '.'); const accessibilityFeaturesProvider = vscode.languages.registerCompletionItemProvider(documentSelector, accessibilityFeaturesCompletionItemProvider, '.'); const tabsProvider = vscode.languages.registerCompletionItemProvider(documentSelector, tabsCompletionItemProvider, '.'); } 方法进行注册。但是,如果我必须像这样继续注册它们,我的激活方法将像1000行长。我是否可以通过某种方式构建它们,例如在activate中注册与tabs相关的所有提供商。
我的tabsCompletionItemProvider.ts看起来像这样:

tabsCompletionItemProvider.ts

任何有关如何构建我的项目的建议都会受到赞赏。

0 个答案:

没有答案