@@ -22,41 +22,65 @@ const localize = nls.loadMessageBundle();
22
22
interface MdServerInitializationOptions extends LsConfiguration { }
23
23
24
24
const organizeLinkDefKind = 'source.organizeLinkDefinitions' ;
25
- export async function startServer ( connection : Connection ) {
25
+
26
+ export async function startVsCodeServer ( connection : Connection ) {
27
+ const logger = new LogFunctionLogger ( connection . console . log . bind ( connection . console ) ) ;
28
+
29
+ const parser = new class implements md . IMdParser {
30
+ slugifier = md . githubSlugifier ;
31
+
32
+ tokenize ( document : md . ITextDocument ) : Promise < md . Token [ ] > {
33
+ return connection . sendRequest ( protocol . parse , { uri : document . uri . toString ( ) } ) ;
34
+ }
35
+ } ;
36
+
26
37
const documents = new TextDocuments ( TextDocument ) ;
27
38
const notebooks = new NotebookDocuments ( documents ) ;
28
39
29
- const configurationManager = new ConfigurationManager ( connection ) ;
40
+ const workspaceFactory : WorkspaceFactory = ( { connection, config, workspaceFolders } ) => {
41
+ const workspace = new VsCodeClientWorkspace ( connection , config , documents , notebooks , logger ) ;
42
+ workspace . workspaceFolders = ( workspaceFolders ?? [ ] ) . map ( x => URI . parse ( x . uri ) ) ;
43
+ return workspace ;
44
+ } ;
30
45
31
- let mdLs : md . IMdLanguageService | undefined ;
32
- let workspace : VsCodeClientWorkspace | undefined ;
46
+ return startServer ( connection , { documents , notebooks , logger , parser , workspaceFactory } ) ;
47
+ }
33
48
34
- connection . onInitialize ( ( params : InitializeParams ) : InitializeResult => {
35
- const parser = new class implements md . IMdParser {
36
- slugifier = md . githubSlugifier ;
49
+ type WorkspaceFactory = ( config : {
50
+ connection : Connection ;
51
+ config : LsConfiguration ;
52
+ workspaceFolders ?: lsp . WorkspaceFolder [ ] | null ;
53
+ } ) => md . IWorkspace ;
54
+
55
+ export async function startServer ( connection : Connection , serverConfig : {
56
+ documents : TextDocuments < md . ITextDocument > ;
57
+ notebooks ?: NotebookDocuments < md . ITextDocument > ;
58
+ logger : md . ILogger ;
59
+ parser : md . IMdParser ;
60
+ workspaceFactory : WorkspaceFactory ;
61
+ } ) {
62
+ const { documents, notebooks } = serverConfig ;
37
63
38
- async tokenize ( document : md . ITextDocument ) : Promise < md . Token [ ] > {
39
- return await connection . sendRequest ( protocol . parse , { uri : document . uri . toString ( ) } ) ;
40
- }
41
- } ;
64
+ let mdLs : md . IMdLanguageService | undefined ;
42
65
66
+ connection . onInitialize ( ( params : InitializeParams ) : InitializeResult => {
43
67
const initOptions = params . initializationOptions as MdServerInitializationOptions | undefined ;
44
68
const config = getLsConfiguration ( initOptions ?? { } ) ;
45
69
46
- const logger = new LogFunctionLogger ( connection . console . log . bind ( connection . console ) ) ;
47
- workspace = new VsCodeClientWorkspace ( connection , config , documents , notebooks , logger ) ;
70
+ const configurationManager = new ConfigurationManager ( connection ) ;
71
+
72
+ const workspace = serverConfig . workspaceFactory ( { connection, config, workspaceFolders : params . workspaceFolders } ) ;
48
73
mdLs = md . createLanguageService ( {
49
74
workspace,
50
- parser,
51
- logger,
75
+ parser : serverConfig . parser ,
76
+ logger : serverConfig . logger ,
52
77
markdownFileExtensions : config . markdownFileExtensions ,
53
78
excludePaths : config . excludePaths ,
54
79
} ) ;
55
80
56
81
registerCompletionsSupport ( connection , documents , mdLs , configurationManager ) ;
57
- registerValidateSupport ( connection , workspace , mdLs , configurationManager , logger ) ;
82
+ registerValidateSupport ( connection , workspace , mdLs , configurationManager , serverConfig . logger ) ;
58
83
59
- workspace . workspaceFolders = ( params . workspaceFolders ?? [ ] ) . map ( x => URI . parse ( x . uri ) ) ;
60
84
return {
61
85
capabilities : {
62
86
diagnosticProvider : {
@@ -212,14 +236,14 @@ export async function startServer(connection: Connection) {
212
236
} ) ) ;
213
237
214
238
documents . listen ( connection ) ;
215
- notebooks . listen ( connection ) ;
239
+ notebooks ? .listen ( connection ) ;
216
240
connection . listen ( ) ;
217
241
}
218
242
219
243
220
244
function registerCompletionsSupport (
221
245
connection : Connection ,
222
- documents : TextDocuments < TextDocument > ,
246
+ documents : TextDocuments < md . ITextDocument > ,
223
247
ls : md . IMdLanguageService ,
224
248
config : ConfigurationManager ,
225
249
) : IDisposable {
0 commit comments