-
-
Save lucasavila00/e7b8014c0d2aec6a8082f2f5b578578d to your computer and use it in GitHub Desktop.
volar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { language } from "@html1/language-core"; | |
import createTypescriptService from "volar-service-typescript"; | |
import { | |
createConnection, | |
startLanguageServer, | |
LanguageServerPlugin, | |
} from "@volar/language-server/node"; | |
const plugin: LanguageServerPlugin = ( | |
_init, | |
{ typescript } | |
): ReturnType<LanguageServerPlugin> => ({ | |
extraFileExtensions: [ | |
{ extension: "md", isMixedContent: true, scriptKind: 7 }, | |
], | |
watchFileExtensions: ["md", "ts", "tsx", "js", "jsx", "cjs", "mjs", "mts"], | |
resolveConfig(config) { | |
if (typescript == null) { | |
throw new Error("no typescript"); | |
} | |
// languages | |
config.languages ??= {}; | |
config.languages.mdts ??= language(typescript); | |
// services | |
config.services ??= {}; | |
config.services.typescript ??= createTypescriptService(); | |
return config; | |
}, | |
}); | |
startLanguageServer(createConnection(), plugin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DiagnosticModel, InitializationOptions } from "@volar/language-server"; | |
import * as vscode from "vscode"; | |
import * as lsp from "vscode-languageclient/node"; | |
// import { activateAutoInsertion } from "@volar/vscode"; | |
let client: lsp.BaseLanguageClient; | |
export async function activate(context: vscode.ExtensionContext) { | |
const serverModule = vscode.Uri.joinPath( | |
context.extensionUri, | |
"dist", | |
"server.js" | |
); | |
const runOptions = { execArgv: <string[]>[] }; | |
const debugOptions = { execArgv: ["--nolazy", "--inspect=" + 6009] }; | |
const serverOptions: lsp.ServerOptions = { | |
run: { | |
module: serverModule.fsPath, | |
transport: lsp.TransportKind.ipc, | |
options: runOptions, | |
}, | |
debug: { | |
module: serverModule.fsPath, | |
transport: lsp.TransportKind.ipc, | |
options: debugOptions, | |
}, | |
}; | |
const initializationOptions: InitializationOptions = { | |
typescript: { | |
tsdk: require("path").join( | |
vscode.env.appRoot, | |
"extensions/node_modules/typescript/lib" | |
), | |
}, | |
diagnosticModel: DiagnosticModel.Pull, | |
}; | |
const clientOptions: lsp.LanguageClientOptions = { | |
documentSelector: [{ language: "markdown" }], | |
initializationOptions, | |
}; | |
client = new lsp.LanguageClient( | |
"html1-language-server", | |
"HTML1 Language Server", | |
serverOptions, | |
clientOptions | |
); | |
await client.start(); | |
// support for auto close tag | |
// activateAutoInsertion([client], (document) => document.languageId === "md"); | |
} | |
export function deactivate(): Thenable<any> | undefined { | |
return client?.stop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment