vscode-languageclient#LanguageClient TypeScript Examples
The following examples show how to use
vscode-languageclient#LanguageClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: extended-language-client.ts From plugin-vscode with Apache License 2.0 | 6 votes |
export class ExtendedLangClient extends LanguageClient {
getSyntaxTree(uri: Uri): Thenable<BallerinaSyntaxTreeResponse> {
const req: GetSyntaxTreeRequest = {
documentIdentifier: {
uri: uri.toString()
}
};
return this.sendRequest("ballerinaDocument/syntaxTree", req);
}
fetchExamples(args: BallerinaExampleListRequest = {}): Thenable<BallerinaExampleListResponse> {
return this.sendRequest("ballerinaExample/list", args);
}
getBallerinaProject(params: GetBallerinaProjectParams): Thenable<BallerinaProject> {
return this.sendRequest("ballerinaPackage/metadata", params);
}
getBallerinaProjectComponents(params: GetBallerinaPackagesParams): Thenable<BallerinaProjectComponents> {
return this.sendRequest("ballerinaPackage/components", params);
}
getSyntaxTreeNode(params: SyntaxTreeNodeRequestParams): Thenable<SyntaxTreeNodeResponse> {
return this.sendRequest("ballerinaDocument/syntaxTreeNode", params);
}
getExecutorPositions(params: GetBallerinaProjectParams): Thenable<ExecutorPositionsResponse> {
return this.sendRequest("ballerinaDocument/executorPositions", params);
}
}
Example #2
Source File: ALLangServerProxy.ts From vscode-alxmldocumentation with MIT License | 5 votes |
private langClient : LanguageClient | undefined;
Example #3
Source File: extension.ts From ui5-language-assistant with Apache License 2.0 | 5 votes |
export async function activate(context: ExtensionContext): Promise<void> {
const debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };
const serverOptions: ServerOptions = {
run: { module: SERVER_PATH, transport: TransportKind.ipc },
debug: {
module: SERVER_PATH,
transport: TransportKind.ipc,
options: debugOptions,
},
};
const meta = JSON.parse(
readFileSync(resolve(context.extensionPath, "package.json"), "utf8")
);
const logLevel = workspace.getConfiguration().get(LOGGING_LEVEL_CONFIG_PROP);
const initializationOptions: ServerInitializationOptions = {
modelCachePath: context.globalStoragePath,
publisher: meta.publisher,
name: meta.name,
// validation of the logLevel value is done on the language server process.
logLevel: logLevel as LogLevel,
};
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: "file", pattern: "**/*.{view,fragment}.xml" }],
synchronize: {
fileEvents: [workspace.createFileSystemWatcher("**/manifest.json")],
},
outputChannelName: meta.displayName,
initializationOptions: initializationOptions,
};
client = new LanguageClient(
"UI5LanguageAssistant",
"UI5 Language Assistant",
serverOptions,
clientOptions
);
client.start();
}
Example #4
Source File: extension.ts From ui5-language-assistant with Apache License 2.0 | 5 votes |
client: LanguageClient
Example #5
Source File: extension.ts From sorbet-lsp with MIT License | 5 votes |
client: LanguageClient
Example #6
Source File: extension.ts From dendron with GNU Affero General Public License v3.0 | 5 votes |
export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(
path.join("server", "out", "server.js")
);
// TODO: don't hradcode
let expressModule = context.asAbsolutePath(
path.join("express-server", "dist", "src", "index.js")
);
// const { app: server } = require(expressModule);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
let debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };
// 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: [{ scheme: "file", language: "markdown" }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
},
};
// Create the language client and start the client.
client = new LanguageClient(
"languageServerExample",
"Language Server Example",
serverOptions,
clientOptions
);
// Start the client. This will also launch the server
client.start();
const port = 3000;
// server.listen(3000, () => {
// console.log("express server started");
// });
}
Example #7
Source File: extension.ts From dendron with GNU Affero General Public License v3.0 | 5 votes |
client: LanguageClient
Example #8
Source File: lsp.ts From dendron with GNU Affero General Public License v3.0 | 5 votes |
export function startClient(opts: { context: ExtensionContext; port: number }) {
const { context, port } = opts;
// The server is implemented in node
const pathToDev = path.join(
__dirname,
"..",
"node_modules",
"@dendronhq",
"lsp-server",
"out",
"server.js"
);
let serverModule: string;
const isDev = fs.existsSync(pathToDev);
if (isDev) {
serverModule = pathToDev;
} else {
serverModule = context.asAbsolutePath(
path.join("dist", "lsp-server", "dist", "server.js")
);
}
const ctx = "startLSPClient";
Logger.info({ ctx, serverModule, isDev, msg: "starting client" });
// TODO: don't hradcode
// let expressModule = context.asAbsolutePath(
// path.join("express-server", "dist", "src", "index.js")
// );
// const { app: server } = require(expressModule);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
const debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions,
},
};
// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: "file", language: "markdown" }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher("dendron.yml"),
},
initializationOptions: {
wsRoot: path.dirname(DendronExtension.workspaceFile().fsPath),
port,
},
};
// Create the language client and start the client.
const client = new LanguageClient(
"dendron.lsp",
"Dendron LSP",
serverOptions,
clientOptions,
true
);
// Start the client. This will also launch the server
client.start();
// const port = 3000;
// server.listen(3000, () => {
// console.log("express server started");
// });
return { client };
}
Example #9
Source File: extension.ts From vscode-groovy-lint with GNU General Public License v3.0 | 5 votes |
client: LanguageClient
Example #10
Source File: extension.ts From reach-ide with Eclipse Public License 2.0 | 5 votes |
export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.js')
);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
let debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
// 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
}
};
terminal = window.createTerminal({ name: 'Reach IDE' });
const reachExecutablePath = workspace.getConfiguration().get('reachide.executableLocation') as string;
const wf = workspace.workspaceFolders[0].uri.path || '.';
const reachPath = (reachExecutablePath === './reach')
? path.join(wf, 'reach')
: reachExecutablePath;
registerCommands(context, reachPath);
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for Reach .rsh documents
documentSelector: [
{
pattern: '**/*.rsh',
scheme: 'file'
}
],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/*.rsh')
}
};
// Create the language client and start the client.
client = new LanguageClient(
'reachide',
'Reach IDE',
serverOptions,
clientOptions
);
// Start the client. This will also launch the server
client.start();
initButtons(context);
// Inject association for .rsh file type
if (workspace.workspaceFolders !== undefined) {
rootFolder = url.fileURLToPath( workspace.workspaceFolders[0].uri.toString() );
}
associateRshFiles();
window.registerTreeDataProvider('reach-commands', new CommandsTreeDataProvider());
window.registerTreeDataProvider('reach-help', new HelpTreeDataProvider());
window.registerTreeDataProvider('reach-docs', new DocumentationTreeDataProvider());
}
Example #11
Source File: extension.ts From reach-ide with Eclipse Public License 2.0 | 5 votes |
client: LanguageClient
Example #12
Source File: extension.ts From sorbet-lsp with MIT License | 4 votes |
export function activate(context: ExtensionContext) {
let disposableClient: Disposable;
const startLanguageServer = () => {
let cmd = [];
let vsconfig = vscode.workspace.getConfiguration('sorbet');
const commandPath = vsconfig.commandPath || 'srb';
const useBundler = vsconfig.useBundler;
const useWatchman = vsconfig.useWatchman;
const bundlerPath = vsconfig.bundlerPath || 'bundle';
if (useBundler) {
cmd = cmd.concat([bundlerPath, 'exec', 'srb']);
} else {
cmd.push(commandPath);
}
cmd = cmd.concat(['tc', '--lsp', '--enable-all-experimental-lsp-features']);
if (!useWatchman) {
cmd.push('--disable-watchman');
}
const firstWorkspace = (workspace.workspaceFolders && workspace.workspaceFolders[0]) ? workspace.workspaceFolders[0].uri.fsPath : null;
if (!existsSync(`${firstWorkspace}/sorbet/config`)) {
vscode.window.showInformationMessage('Sorbet config not found. Sorbet server will not be started');
return;
}
const env = commonOptions(firstWorkspace);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
let debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
const serverOptions: ServerOptions = () => {
return new Promise((resolve) => {
let child = spawnWithBash(cmd, env);
child.stderr.on('data', (data: Buffer) => {
console.log(data.toString());
});
child.on('exit', (code, signal) => {
console.log('Sorbet exited with code', code, signal);
});
resolve(child);
});
}
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: 'file', language: 'ruby' }],
synchronize: {
// Notify the server about changes to relevant files in the workspace
fileEvents: workspace.createFileSystemWatcher('{**/*.rb,**/*.gemspec,**/Gemfile}')
},
outputChannelName: 'Sorbet Language Server',
revealOutputChannelOn: RevealOutputChannelOn.Never
};
// Create the language client and start the client.
client = new LanguageClient(
'sorbetLanguageServer',
'Sorbet Language Server',
serverOptions,
clientOptions
);
// Start the client. This will also launch the server
disposableClient = client.start();
}
const restartLanguageServer = function (): Promise<void> {
return new Promise((resolve) => {
if (disposableClient) {
client.stop().then(() => {
disposableClient.dispose();
startLanguageServer();
resolve();
});
} else {
startLanguageServer();
resolve();
}
});
}
// Restart command
var disposableRestart = vscode.commands.registerCommand('sorbet.restart', () => {
restartLanguageServer().then(() => {
vscode.window.showInformationMessage('Sorbet server restarted.');
});
});
context.subscriptions.push(disposableRestart);
startLanguageServer();
}
Example #13
Source File: extension.ts From vscode-groovy-lint with GNU General Public License v3.0 | 4 votes |
export function activate(context: ExtensionContext) {
// Create diagnostics collection
diagnosticsCollection = vscode.languages.createDiagnosticCollection(DIAGNOSTICS_COLLECTION_NAME);
///////////////////////////////////////////////
/////////////// Server + client ///////////////
///////////////////////////////////////////////
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'server.js'));
// 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: {
execArgv: ['--nolazy', '--inspect=6009'],
env: { "DEBUG": "vscode-groovy-lint,npm-groovy-lint" }
}
}
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for groovy documents
documentSelector: [{ scheme: 'file', language: 'groovy' }],
diagnosticCollectionName: DIAGNOSTICS_COLLECTION_NAME,
progressOnInitialization: true,
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
}
};
// Create the language client and start the client.
client = new LanguageClient(
'groovyLint',
'Groovy Lint',
serverOptions,
clientOptions
);
// Manage status bar item (with loading icon)
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
statusBarItem.command = 'groovyLint.lint';
statusBarItem.text = 'GroovyLint $(clock~spin)';
statusBarItem.show();
client.registerProposedFeatures();
// Start the client. This will also launch the server
context.subscriptions.push(
client.start()
);
// Actions after client is ready
client.onReady().then(() => {
// Show status bar item to display & run groovy lint
refreshStatusBar();
// Manage status notifications
client.onNotification(StatusNotification.type, async (status) => {
await updateStatus(status);
});
// Open file in workspace when language server requests it
client.onNotification(OpenNotification.type, async (notifParams: any) => {
// Open textDocument from file path
if (notifParams.file) {
const openPath = vscode.Uri.parse("file:///" + notifParams.file); //A request file path
const doc = await vscode.workspace.openTextDocument(openPath);
await vscode.window.showTextDocument(doc, {
preserveFocus: true,
// eslint-disable-next-line eqeqeq
preview: (notifParams.preview != null) ? notifParams.preview : true
});
}
// Open textDocument from URI
else if (notifParams.uri) {
const openPath = vscode.Uri.parse(notifParams.uri); //A request file path
const doc = await vscode.workspace.openTextDocument(openPath);
await vscode.window.showTextDocument(doc, {
preserveFocus: true,
// eslint-disable-next-line eqeqeq
preview: (notifParams.preview != null) ? notifParams.preview : true
});
}
// Open url in external browser
else if (notifParams.url) {
await vscode.env.openExternal(notifParams.url);
}
});
// Refresh status bar when active tab changes
vscode.window.onDidChangeActiveTextEditor(async () => {
await refreshStatusBar();
await notifyDocumentToServer();
});
});
}