-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.ts
155 lines (132 loc) · 4.42 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import * as shvl from "shvl";
import { InitializeParams, TextDocumentSyncKind } from "vscode-languageserver";
import { projectRootPatterns } from "./common/constant";
import { IConfig, IDiagnostic, IIndexes, ISuggest } from "./common/types";
import { completionProvider } from "./handles/completion";
import { completionResolveProvider } from "./handles/completionResolve";
import { definitionProvider } from "./handles/definition";
import { documentHighlightProvider } from "./handles/documentHighlight";
import {foldingRangeProvider} from "./handles/foldingRange";
import { hoverProvider } from "./handles/hover";
import { referencesProvider } from "./handles/references";
import { prepareProvider, renameProvider } from "./handles/rename";
import { signatureHelpProvider } from "./handles/signatureHelp";
import { builtinDocs } from "./server/builtin";
import config from "./server/config";
import { connection } from "./server/connection";
import { documents } from "./server/documents";
import { next, unsubscribe } from "./server/parser";
import {selectionRangeProvider} from "./handles/selectionRange";
import {documentSymbolProvider} from "./handles/documentSymbol";
import logger from "./common/logger";
// lsp initialize
connection.onInitialize((param: InitializeParams) => {
const renamePrepareSupport = param.capabilities.textDocument && param.capabilities.textDocument.rename && param.capabilities.textDocument.rename.prepareSupport === true;
const { initializationOptions = {} } = param;
const {
isNeovim,
iskeyword,
runtimepath,
vimruntime,
diagnostic,
suggest,
indexes,
}: {
isNeovim: boolean
iskeyword: string
runtimepath: string
vimruntime: string
diagnostic: IDiagnostic
suggest: ISuggest
indexes: IIndexes,
} = initializationOptions;
const runtimepaths = runtimepath ? runtimepath.split(",") : [];
// config by user's initializationOptions
const conf: IConfig = {
isNeovim: isNeovim || false,
iskeyword: iskeyword || "",
runtimepath: runtimepaths,
vimruntime: (vimruntime || "").trim(),
diagnostic: {
enable: true,
...(diagnostic || {}),
},
snippetSupport: shvl.get(param, "capabilities.textDocument.completion.completionItem.snippetSupport"),
suggest: {
fromRuntimepath: false,
fromVimruntime: true,
...(suggest || {}),
},
indexes: {
runtimepath: true,
gap: 100,
count: 1,
projectRootPatterns,
...(indexes || {}),
},
capabilities: param.capabilities
};
// init config
config.init(conf);
// init builtin docs
builtinDocs.init();
return {
capabilities: {
textDocumentSync: TextDocumentSyncKind.Incremental,
documentHighlightProvider: true,
foldingRangeProvider: true,
selectionRangeProvider: true,
documentSymbolProvider: true,
hoverProvider: true,
completionProvider: {
triggerCharacters: [".", ":", "#", "[", "&", "$", "<", '"', "'"],
resolveProvider: true,
},
signatureHelpProvider: {
triggerCharacters: ["(", ","],
},
definitionProvider: true,
referencesProvider: true,
renameProvider: renamePrepareSupport ? {
prepareProvider: true,
} : true,
},
};
});
// document change or open
documents.onDidChangeContent(( change ) => {
next(change.document);
});
documents.onDidClose((evt) => {
unsubscribe(evt.document);
});
// listen for document's open/close/change
documents.listen(connection);
// handle completion
connection.onCompletion(completionProvider);
// handle completion resolve
connection.onCompletionResolve(completionResolveProvider);
// handle signature help
connection.onSignatureHelp(signatureHelpProvider);
// handle hover
connection.onHover(hoverProvider);
// handle definition request
connection.onDefinition(definitionProvider);
// handle references
connection.onReferences(referencesProvider);
// handle rename
connection.onPrepareRename(prepareProvider);
connection.onRenameRequest(renameProvider);
// document highlight
connection.onDocumentHighlight(documentHighlightProvider);
// folding range
connection.onFoldingRanges(foldingRangeProvider);
// select range
connection.onSelectionRanges(selectionRangeProvider);
// document symbols
connection.onDocumentSymbol(documentSymbolProvider);
connection.onNotification('$/change/iskeyword', (iskeyword: string) => {
config.changeByKey('iskeyword', iskeyword)
})
// lsp start
connection.listen();