Skip to content

Commit

Permalink
Add "vetur.restartVLS" command (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaegassy committed Mar 8, 2021
1 parent 7f8ce0d commit ec2b980
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,14 @@
"description": "Enable template interpolation service that offers hover / definition / references in Vue interpolations."
}
}
}
},
"commands": [
{
"command": "vetur.restartVLS",
"category": "Vetur",
"title": "Restart VLS (Vue Language Server)"
}
]
},
"author": "chemzqm@gmail.com",
"license": "MIT",
Expand Down
29 changes: 28 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtensionContext, LanguageClient, LanguageClientOptions, ProvideCompletionItemsSignature, ServerOptions, services, TransportKind, window, workspace, WorkspaceConfiguration } from 'coc.nvim'
import { commands, ExtensionContext, LanguageClient, LanguageClientOptions, ProvideCompletionItemsSignature, ServerOptions, services, TransportKind, window, workspace, WorkspaceConfiguration } from 'coc.nvim'
import fs from 'fs'
import os from 'os'
import path from 'path'
Expand Down Expand Up @@ -93,6 +93,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
let client = new LanguageClient('vetur', 'Vetur Language Server', serverOptions, clientOptions)
client.onReady().then(() => {
registerCustomClientNotificationHandlers(client)
registerRestartVLSCommand(context, client)
}).catch(_e => {
// noop
})
Expand All @@ -102,6 +103,32 @@ export async function activate(context: ExtensionContext): Promise<void> {
)
}

async function displayInitProgress<T = void>(promise: Promise<T>) {
return window.withProgress(
{
title: 'Vetur initialization',
cancellable: true
},
() => promise
)
}

function registerRestartVLSCommand(
context: ExtensionContext,
client: LanguageClient
) {
context.subscriptions.push(
commands.registerCommand('vetur.restartVLS', () =>
displayInitProgress(
client
.stop()
.then(() => client.start())
.then(() => client.onReady())
)
)
)
}

function registerCustomClientNotificationHandlers(client: LanguageClient): void {
client.onNotification('$/displayInfo', (msg: string) => {
window.showMessage(msg, 'more')
Expand Down

0 comments on commit ec2b980

Please sign in to comment.