Skip to content

Instantly share code, notes, and snippets.

@etherealHero
Created June 24, 2025 04:18
Show Gist options
  • Save etherealHero/6a981ec0c38f29b512c1f18e7b8fa9b7 to your computer and use it in GitHub Desktop.
Save etherealHero/6a981ec0c38f29b512c1f18e7b8fa9b7 to your computer and use it in GitHub Desktop.
Example MSSQL Language server support in VS Code by extension
/**
* Example MSSQL Language server support in VS Code
*/
import { LanguageClient, ServerOptions, TransportKind, LanguageClientOptions } from "vscode-languageclient";
import * as vscode from "vscode";
let client: LanguageClient;
export async function activate(context: vscode.ExtensionContext) {
const serverOptions: ServerOptions = {
command: "path\\to\\MicrosoftSqlToolsServiceLayer.exe",
args: [
"--log-file",
"path\\log\\sqltools.log",
"--tracing-level",
"Critical",
"--application-name",
"Code",
"--data-path",
"C:\\Users\\<User>\\AppData\\Roaming",
"--enable-sql-authentication-provider"
],
transport: TransportKind.stdio
};
const clientOptions: LanguageClientOptions = {
documentSelector: ["sql"],
diagnosticCollectionName: "mssql"
};
client = new LanguageClient("SQLToolsService", serverOptions, clientOptions);
context.subscriptions.push(client.start());
await client.onReady();
client.onNotification("textDocument/intelliSenseReady", () => {
console.log("IntelliSenseReady");
});
console.log("client ready");
if (!vscode.window.activeTextEditor?.document.uri.toString(true)) return;
const params = {
ownerUri: vscode.window.activeTextEditor.document.uri.toString(true),
connection: {
options: {
server: "<server>",
database: "<database>",
databaseDisplayName: "<database>",
authenticationType: "Integrated",
encrypt: "Mandatory",
trustServerCertificate: true,
connectTimeout: 15,
commandTimeout: 30,
applicationName: "mssql"
}
}
};
await client.sendRequest("connection/connect", params);
console.log("connected");
}
export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment