本文整理汇总了TypeScript中vscode.ExtensionContext类的典型用法代码示例。如果您正苦于以下问题:TypeScript ExtensionContext类的具体用法?TypeScript ExtensionContext怎么用?TypeScript ExtensionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExtensionContext类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: activate
export function activate(context: ExtensionContext) {
let serverOptions : ServerOptions;
if (ideConfig["backend"] == "scry") {
let arch : string = os.arch();
let platform : string = os.platform();
let command : string = context.asAbsolutePath(path.join("scry", platform, arch, "scry"));
serverOptions = { command: command, args: [] };
}
else if (ideConfig["backend"] == "custom") {
let command : string = ideConfig["customCommand"];
let args : [string] = ideConfig["customCommandArgs"] || [];
serverOptions = { command: command, args: args}
} else {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'server.js'));
// The debug options for the server
let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
serverOptions = {
run : { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
}
}
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for Crystal source files
documentSelector: ['crystal'],
synchronize: {
// Synchronize the setting section to the server
configurationSection: 'crystal-ide',
// Notify the server about file changes to crystal files
fileEvents: workspace.createFileSystemWatcher('**/*.cr')
}
}
// Create the language client and start the client.
let disposable = new LanguageClient('Crystal Language', serverOptions, clientOptions).start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
}
示例2: activate
export function activate(context: ExtensionContext) {
// lokalizacja modułu Node.js serwera
let serverModule = context.asAbsolutePath(path.join('server', 'server.js'));
// ustawienia umożliwiające debugowanie kodu serwera
let debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };
// ustawienia serwera
let serverOptions: ServerOptions = {
run : { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
}
// opcje klienta
let clientOptions: LanguageClientOptions = {
documentSelector: [{scheme: 'file', language: 'lua'}],
synchronize: {
configurationSection: 'lua-lang',
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
}
}
// Uruchomienie klienta LSP
let client = new LanguageClient('luaLanguage', 'Lua language extension', serverOptions, clientOptions).start();
// Dodanie klienta do kolekcji elementów usuwanych przy zamknięciu rozszerzenia
context.subscriptions.push(client);
}
示例3: init
async function init(context: ExtensionContext, outputChannel: OutputChannel, disposables: Disposable[]): Promise<Model> {
const { name, version, aiKey } = require(context.asAbsolutePath('./package.json')) as { name: string, version: string, aiKey: string };
const telemetryReporter: TelemetryReporter = new TelemetryReporter(name, version, aiKey);
disposables.push(telemetryReporter);
const pathHint = workspace.getConfiguration('git').get<string>('path');
const info = await findGit(pathHint, path => outputChannel.appendLine(localize('looking', "Looking for git in: {0}", path)));
const askpass = new Askpass();
const env = await askpass.getEnv();
const git = new Git({ gitPath: info.path, version: info.version, env });
const model = new Model(git, context.globalState);
disposables.push(model);
const onRepository = () => commands.executeCommand('setContext', 'gitOpenRepositoryCount', `${model.repositories.length}`);
model.onDidOpenRepository(onRepository, null, disposables);
model.onDidCloseRepository(onRepository, null, disposables);
onRepository();
outputChannel.appendLine(localize('using git', "Using git {0} from {1}", info.version, info.path));
const onOutput = (str: string) => outputChannel.append(str);
git.onOutput.addListener('log', onOutput);
disposables.push(toDisposable(() => git.onOutput.removeListener('log', onOutput)));
disposables.push(
new CommandCenter(git, model, outputChannel, telemetryReporter),
new GitContentProvider(model),
new GitDecorations(model)
);
await checkGitVersion(info);
return model;
}
示例4: activate
export function activate(context: ExtensionContext) {
let packageInfo = getPackageInfo(context);
let telemetryReporter: TelemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
context.subscriptions.push(telemetryReporter);
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'jsonServerMain.js'));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--debug=6004'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for json documents
documentSelector: ['json'],
synchronize: {
// Synchronize the setting section 'json' to the server
configurationSection: ['json', 'http.proxy', 'http.proxyStrictSSL'],
fileEvents: workspace.createFileSystemWatcher('**/*.json')
}
};
// Create the language client and start the client.
let client = new LanguageClient('json', localize('jsonserver.name', 'JSON Language Server'), serverOptions, clientOptions);
let disposable = client.start();
client.onReady().then(() => {
client.onTelemetry(e => {
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(e.key, e.data);
}
});
// handle content request
client.onRequest(VSCodeContentRequest.type, (uriPath: string) => {
let uri = Uri.parse(uriPath);
return workspace.openTextDocument(uri).then(doc => {
return doc.getText();
}, error => {
return Promise.reject(error);
});
});
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
});
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
languages.setLanguageConfiguration('json', {
wordPattern: /("(?:[^\\\"]*(?:\\.)?)*"?)|[^\s{}\[\],:]+/
});
}
示例5: activate
export function activate(context: ExtensionContext) {
// The language server is implemented in C#
let serverProgram = context.asAbsolutePath(path.join('server', 'TypeCobol.LanguageServer.exe'));
// Command line options for the language server
let serverTraceOptions = [ "2", // Trace level : 0 Lifecycle, 1 Message, 2 Protocol
"TypeCobol.LanguageServer.txt" // Log file
];
// Options to launch the language server
let serverOptions: Executable = {
command: serverProgram,
args: serverTraceOptions
}
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for TypeCobol documents
documentSelector: ['typecobol'],
synchronize: {
// Synchronize the setting section 'typecobol' to the server
configurationSection: 'typecobol',
// Notify the server about file changes to '.cpy' files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.cpy')
}
}
// Create the language client and start the client.
let disposable = new LanguageClient('TypeCobol', serverOptions, clientOptions).start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
}
示例6: activate
export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'serverMain.js'));
// The debug options for the server
let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
}
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: ['plaintext'],
synchronize: {
// Synchronize the setting section 'languageServerExample' to the server
configurationSection: 'languageServerExample',
// Notify the server about file changes to '.clientrc files contain in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
}
}
// Create the language client and start the client.
let disposable = new LanguageClient('languageServerExample', 'Language Server Example', serverOptions, clientOptions).start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
}
示例7: activate
export function activate(context: ExtensionContext) {
// Construct the path to the language server
const serverModule = context.asAbsolutePath(
join('node_modules', '.bin', 'kythe-languageserver'));
const debugOptions = {execArgv: ['--nolazy', '--debug=6009']};
const serverOptions = {
run: {module: serverModule, transport: TransportKind.ipc},
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
},
};
const clientOptions: LanguageClientOptions = {
// Activate on all files and defer to the server to ignore stuff
documentSelector: [{pattern: '**/*'}]
}
const disposable = new LanguageClient(
'kytheLanguageServer', 'Kythe Language Server',
serverOptions, clientOptions)
.start();
context.subscriptions.push(disposable);
}
示例8: activate
export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'src', 'server.js'));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--debug=6004'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run : { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: ['haskell'],
synchronize: {
// Synchronize the setting section 'ghcMod' to the server
configurationSection: 'haskell.ghcMod'
}
};
// Create the language client and start the client.
let disposable = new LanguageClient('ghc-mod server', serverOptions, clientOptions).start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
}
示例9: activate
export function activate(context: ExtensionContext): API {
const config = workspace.getConfiguration('git', null);
const enabled = config.get<boolean>('enabled');
const disposables: Disposable[] = [];
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()));
const { name, version, aiKey } = require(context.asAbsolutePath('./package.json')) as { name: string, version: string, aiKey: string };
telemetryReporter = new TelemetryReporter(name, version, aiKey);
let activatePromise: Promise<Model | undefined>;
if (enabled) {
activatePromise = _activate(context, disposables);
} else {
const onConfigChange = filterEvent(workspace.onDidChangeConfiguration, e => e.affectsConfiguration('git'));
const onEnabled = filterEvent(onConfigChange, () => workspace.getConfiguration('git', null).get<boolean>('enabled') === true);
activatePromise = eventToPromise(onEnabled)
.then(() => _activate(context, disposables));
}
const modelPromise = activatePromise
.then(model => model || Promise.reject<Model>('Git model not found'));
activatePromise.catch(err => console.error(err));
return createApi(modelPromise);
}
示例10: activate
export function activate(context: ExtensionContext)
{
let qol: QualityOfLife = new QualityOfLife();
let serverModule = context.asAbsolutePath(path.join("server", "server.js"));
let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };
let serverOptions: ServerOptions = {
run : { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
}
let clientOptions: LanguageClientOptions = {
documentSelector: ["php"],
synchronize: {
configurationSection: "languageServerExample",
fileEvents: workspace.createFileSystemWatcher("**/.clientrc")
}
}
// Create the language client and start the client.
var langClient: LanguageClient = new LanguageClient("Crane Language Server", serverOptions, clientOptions);
// Use this to handle a request sent from the server
// https://github.com/Microsoft/vscode/blob/80bd73b5132268f68f624a86a7c3e56d2bbac662/extensions/json/client/src/jsonMain.ts
// https://github.com/Microsoft/vscode/blob/580d19ab2e1fd6488c3e515e27fe03dceaefb819/extensions/json/server/src/server.ts
//langClient.onRequest()
let disposable = langClient.start();
let crane: Crane = new Crane(langClient);
var requestType: RequestType<any, any, any> = { method: "workDone" };
langClient.onRequest(requestType, () => {
// Load settings
let craneSettings = workspace.getConfiguration("crane");
if (craneSettings) {
var showStatusBarItem = craneSettings.get<boolean>("showStatusBarBugReportLink", true);
if (showStatusBarItem) {
setTimeout(() => {
crane.statusBarItem.text = "$(bug) Report PHP Intellisense Bug";
crane.statusBarItem.tooltip = "Found a problem with the PHP Intellisense provided by Crane? Click here to file a bug report on Github";
crane.statusBarItem.command = "crane.reportBug";
crane.statusBarItem.show();
}, 5000);
} else {
crane.statusBarItem.hide();
}
} else {
crane.statusBarItem.hide();
}
});
// Register commands for QoL improvements
let duplicateLineCommand = commands.registerCommand("crane.duplicateLine", qol.duplicateLineOrSelection);
let reportBugCommand = commands.registerCommand("crane.reportBug", crane.reportBug);
context.subscriptions.push(disposable);
context.subscriptions.push(duplicateLineCommand);
}