-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextension.ts
51 lines (42 loc) · 1.61 KB
/
extension.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import path from 'path'
import fs from 'fs'
import { ExtensionContext, LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, commands, services, window, workspace } from 'coc.nvim'
interface ShConfig {
enable: boolean
commandPath: string
highlightParsingErrors: boolean
explainshellEndpoint: string
globPattern: string
}
export async function activate(context: ExtensionContext): Promise<void> {
const config = workspace.getConfiguration().get('sh', {}) as ShConfig
if (config.enable === false) {
return
}
// TODO add config options:
const serverOptions: ServerOptions = {
command: (config.commandPath || require.resolve('bash-language-server/out/cli.js')),
args: ['start'],
transport: TransportKind.stdio,
options: {
env: {
// => https://github.com/bash-lsp/bash-language-server/blob/master/server/src/config.ts
EXPLAINSHELL_ENDPOINT: config.explainshellEndpoint,
GLOB_PATTERN: config.globPattern,
HIGHLIGHT_PARSING_ERRORS: config.highlightParsingErrors.toString()
}
}
}
const clientOptions: LanguageClientOptions = {
documentSelector: ['sh']
}
const client = new LanguageClient('sh', 'bash-language-server', serverOptions, clientOptions)
context.subscriptions.push(
services.registLanguageClient(client),
commands.registerCommand("sh.version", async () => {
const rootDir = path.join(__dirname, '..')
const { version } = JSON.parse(fs.readFileSync(path.resolve(rootDir, 'package.json'), 'utf-8'))
window.showInformationMessage(`Version: ${version} [node: ${process.versions.node}]`)
})
)
}