mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
81 lines
1.8 KiB
TypeScript
81 lines
1.8 KiB
TypeScript
import * as path from "path"
|
|
import { ExtensionContext, workspace } from 'vscode';
|
|
|
|
import {
|
|
Executable,
|
|
LanguageClient,
|
|
type LanguageClientOptions,
|
|
type ServerOptions,
|
|
} from 'vscode-languageclient/node';
|
|
|
|
const IS_DEBUG = process.env.VSCODE_DEBUG_MODE === 'true' || process.env.NODE_ENV === 'development';
|
|
let client: LanguageClient;
|
|
|
|
export function activate(context: ExtensionContext) {
|
|
console.info("config-lsp activated");
|
|
const initOptions = workspace.getConfiguration('config-lsp');
|
|
const clientOptions: LanguageClientOptions = {
|
|
documentSelector: [
|
|
{
|
|
scheme: 'file',
|
|
language: 'plaintext',
|
|
pattern: "**/{config,sshconfig,sshd_config,sshdconfig,fstab,hosts,aliases}",
|
|
},
|
|
// Some configs seem to be incorrectly detected as yaml
|
|
{
|
|
scheme: 'file',
|
|
language: 'yaml',
|
|
pattern: "**/{config,sshconfig,sshd_config,sshdconfig,fstab,hosts,aliases}",
|
|
},
|
|
],
|
|
initializationOptions: initOptions,
|
|
};
|
|
|
|
const path = getBundledPath();
|
|
console.info(`Found config-lsp path at ${path}`);
|
|
const run: Executable = {
|
|
command: getBundledPath(),
|
|
}
|
|
const serverOptions: ServerOptions = {
|
|
run,
|
|
debug: run,
|
|
}
|
|
|
|
client = new LanguageClient(
|
|
'config-lsp',
|
|
serverOptions,
|
|
clientOptions,
|
|
IS_DEBUG,
|
|
);
|
|
|
|
|
|
client.start();
|
|
console.info("config-lsp started");
|
|
|
|
// const serverOptions: ServerOptions = {
|
|
// }
|
|
//
|
|
// // Create the language client and start the client.
|
|
// client = new LanguageClient(
|
|
// 'languageServerExample',
|
|
// clientOptions
|
|
// );
|
|
//
|
|
// // Start the client. This will also launch the server
|
|
// client.start();
|
|
}
|
|
|
|
function getBundledPath(): string {
|
|
const filePath = path.resolve(__dirname, "config-lsp")
|
|
|
|
return filePath;
|
|
}
|
|
|
|
export function deactivate(): Thenable<void> | undefined {
|
|
if (!client) {
|
|
return undefined;
|
|
}
|
|
|
|
return client.stop();
|
|
}
|