diff options
Diffstat (limited to 'extensions/markdown-language-features/src/client.ts')
-rw-r--r-- | extensions/markdown-language-features/src/client.ts | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/extensions/markdown-language-features/src/client.ts b/extensions/markdown-language-features/src/client.ts index aabd09f4633..96b43406961 100644 --- a/extensions/markdown-language-features/src/client.ts +++ b/extensions/markdown-language-features/src/client.ts @@ -5,7 +5,7 @@ import Token = require('markdown-it/lib/token'); import * as vscode from 'vscode'; -import { BaseLanguageClient, LanguageClientOptions, RequestType } from 'vscode-languageclient'; +import { BaseLanguageClient, LanguageClientOptions, NotebookDocumentSyncRegistrationType, RequestType } from 'vscode-languageclient'; import * as nls from 'vscode-nls'; import { IMdParser } from './markdownEngine'; import { markdownFileExtensions } from './util/file'; @@ -14,9 +14,9 @@ import { IMdWorkspace } from './workspace'; const localize = nls.loadMessageBundle(); const parseRequestType: RequestType<{ uri: string }, Token[], any> = new RequestType('markdown/parse'); - const readFileRequestType: RequestType<{ uri: string }, number[], any> = new RequestType('markdown/readFile'); - +const statFileRequestType: RequestType<{ uri: string }, { isDirectory: boolean } | undefined, any> = new RequestType('markdown/statFile'); +const readDirectoryRequestType: RequestType<{ uri: string }, [string, { isDirectory: boolean }][], any> = new RequestType('markdown/readDirectory'); const findFilesRequestTypes: RequestType<{}, string[], any> = new RequestType('markdown/findFiles'); export type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => BaseLanguageClient; @@ -24,22 +24,36 @@ export type LanguageClientConstructor = (name: string, description: string, clie export async function startClient(factory: LanguageClientConstructor, workspace: IMdWorkspace, parser: IMdParser): Promise<BaseLanguageClient> { - const documentSelector = ['markdown']; const mdFileGlob = `**/*.{${markdownFileExtensions.join(',')}}`; const clientOptions: LanguageClientOptions = { - documentSelector, + documentSelector: [{ language: 'markdown' }], synchronize: { configurationSection: ['markdown'], fileEvents: vscode.workspace.createFileSystemWatcher(mdFileGlob), }, - initializationOptions: {} + initializationOptions: { + markdownFileExtensions, + } }; const client = factory('markdown', localize('markdownServer.name', 'Markdown Language Server'), clientOptions); client.registerProposedFeatures(); + const notebookFeature = client.getFeature(NotebookDocumentSyncRegistrationType.method); + if (notebookFeature !== undefined) { + notebookFeature.register({ + id: String(Date.now()), + registerOptions: { + notebookSelector: [{ + notebook: '*', + cells: [{ language: 'markdown' }] + }] + } + }); + } + client.onRequest(parseRequestType, async (e) => { const uri = vscode.Uri.parse(e.uri); const doc = await workspace.getOrLoadMarkdownDocument(uri); @@ -55,6 +69,22 @@ export async function startClient(factory: LanguageClientConstructor, workspace: return Array.from(await vscode.workspace.fs.readFile(uri)); }); + client.onRequest(statFileRequestType, async (e): Promise<{ isDirectory: boolean } | undefined> => { + const uri = vscode.Uri.parse(e.uri); + try { + const stat = await vscode.workspace.fs.stat(uri); + return { isDirectory: stat.type === vscode.FileType.Directory }; + } catch { + return undefined; + } + }); + + client.onRequest(readDirectoryRequestType, async (e): Promise<[string, { isDirectory: boolean }][]> => { + const uri = vscode.Uri.parse(e.uri); + const result = await vscode.workspace.fs.readDirectory(uri); + return result.map(([name, type]) => [name, { isDirectory: type === vscode.FileType.Directory }]); + }); + client.onRequest(findFilesRequestTypes, async (): Promise<string[]> => { return (await vscode.workspace.findFiles(mdFileGlob, '**/node_modules/**')).map(x => x.toString()); }); |