diff options
Diffstat (limited to 'vscode/packages/client/src/index.ts')
-rw-r--r-- | vscode/packages/client/src/index.ts | 73 |
1 files changed, 30 insertions, 43 deletions
diff --git a/vscode/packages/client/src/index.ts b/vscode/packages/client/src/index.ts index c7233892b..9ed016eb0 100644 --- a/vscode/packages/client/src/index.ts +++ b/vscode/packages/client/src/index.ts @@ -1,21 +1,22 @@ import * as path from 'path'; import * as vscode from 'vscode'; import * as lsp from 'vscode-languageclient/node'; - -import * as defaultSettings from './features/defaultSettings.js'; +import { activateTagClosing } from './html/autoClose'; let docClient: lsp.LanguageClient; +const TagCloseRequest: lsp.RequestType<lsp.TextDocumentPositionParams, string, any> = new lsp.RequestType('html/tag'); + +/** */ export async function activate(context: vscode.ExtensionContext) { docClient = createLanguageService(context, 'doc', 'astro', 'Astro', 6040); - defaultSettings.activate(); - await docClient.onReady(); - startEmbeddedLanguageServices(); } +/** */ function createLanguageService(context: vscode.ExtensionContext, mode: 'doc', id: string, name: string, port: number) { + const { workspace } = vscode; const serverModule = context.asAbsolutePath(path.join('dist', 'server.js')); const debugOptions = { execArgv: ['--nolazy', '--inspect=' + port] }; const serverOptions: lsp.ServerOptions = { @@ -33,47 +34,33 @@ function createLanguageService(context: vscode.ExtensionContext, mode: 'doc', id }; const clientOptions: lsp.LanguageClientOptions = { documentSelector: [{ scheme: 'file', language: 'astro' }], - initializationOptions: serverInitOptions, + synchronize: { + configurationSection: ['javascript', 'typescript', 'prettier'], + fileEvents: workspace.createFileSystemWatcher('{**/*.js,**/*.ts}', false, false, false), + }, + initializationOptions: { + ...serverInitOptions, + configuration: { + prettier: workspace.getConfiguration('prettier'), + emmet: workspace.getConfiguration('emmet'), + typescript: workspace.getConfiguration('typescript'), + javascript: workspace.getConfiguration('javascript'), + }, + dontFilterIncompleteCompletions: true, // VSCode filters client side and is smarter at it than us + }, }; const client = new lsp.LanguageClient(id, name, serverOptions, clientOptions); - context.subscriptions.push(client.start()); - return client; -} - -async function startEmbeddedLanguageServices() { - const ts = vscode.extensions.getExtension('vscode.typescript-language-features'); - const css = vscode.extensions.getExtension('vscode.css-language-features'); - const html = vscode.extensions.getExtension('vscode.html-language-features'); - - if (ts && !ts.isActive) { - await ts.activate(); - } - if (css && !css.isActive) { - await css.activate(); - } - if (html && !html.isActive) { - await html.activate(); - } + context.subscriptions.push(client.start()); - /* from html-language-features */ - const EMPTY_ELEMENTS: string[] = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']; - vscode.languages.setLanguageConfiguration('astro', { - indentationRules: { - increaseIndentPattern: /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|link|meta|param)\b|[^>]*\/>)([-_\.A-Za-z0-9]+)(?=\s|>)\b[^>]*>(?!.*<\/\1>)|<!--(?!.*-->)|\{[^}"']*$/, - decreaseIndentPattern: /^\s*(<\/(?!html)[-_\.A-Za-z0-9]+\b[^>]*>|-->|\})/, - }, - wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g, - onEnterRules: [ - { - beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), - afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>/i, - action: { indentAction: vscode.IndentAction.IndentOutdent }, - }, - { - beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), - action: { indentAction: vscode.IndentAction.Indent }, - }, - ], + client.onReady().then(() => { + const tagRequestor = (document: vscode.TextDocument, position: vscode.Position) => { + const param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position); + return client.sendRequest(TagCloseRequest, param); + }; + const disposable = activateTagClosing(tagRequestor, { astro: true }, 'html.autoClosingTags'); + context.subscriptions.push(disposable); }); + + return client; } |