vscode-languageclient#TransportKind TypeScript Examples
The following examples show how to use
vscode-languageclient#TransportKind.
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: 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 #2
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 #3
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 #4
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 #5
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();
});
});
}