From 077f5865dac519a9ce6145b39065cee0b5952232 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 6 Sep 2022 22:17:41 -0700 Subject: [PATCH] Support latest md ls (#160228) - Update `looksLikeMarkdownPath` to look at open documents and notebooks, not just the uri - Register custom command for document links --- .../markdown-language-features/src/client.ts | 5 ++++- .../src/util/file.ts | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/extensions/markdown-language-features/src/client.ts b/extensions/markdown-language-features/src/client.ts index f52cfbe8136..59952aaa87b 100644 --- a/extensions/markdown-language-features/src/client.ts +++ b/extensions/markdown-language-features/src/client.ts @@ -40,7 +40,6 @@ export async function startClient(factory: LanguageClientConstructor, workspace: return looksLikeMarkdownPath(resource); }, }, - }; const client = factory('markdown', localize('markdownServer.name', 'Markdown Language Server'), clientOptions); @@ -116,6 +115,10 @@ export async function startClient(factory: LanguageClientConstructor, workspace: watchers.delete(params.id); }); + vscode.commands.registerCommand('vscodeMarkdownLanguageservice.open', (uri, args) => { + return vscode.commands.executeCommand('vscode.open', uri, args); + }); + await client.start(); return client; diff --git a/extensions/markdown-language-features/src/util/file.ts b/extensions/markdown-language-features/src/util/file.ts index e97ab743929..9a4990a0585 100644 --- a/extensions/markdown-language-features/src/util/file.ts +++ b/extensions/markdown-language-features/src/util/file.ts @@ -5,6 +5,7 @@ import * as vscode from 'vscode'; import * as URI from 'vscode-uri'; +import { Schemes } from './schemes'; export const markdownFileExtensions = Object.freeze([ 'md', @@ -22,6 +23,22 @@ export function isMarkdownFile(document: vscode.TextDocument) { return document.languageId === 'markdown'; } -export function looksLikeMarkdownPath(resolvedHrefPath: vscode.Uri) { +export function looksLikeMarkdownPath(resolvedHrefPath: vscode.Uri): boolean { + const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === resolvedHrefPath.toString()); + if (doc) { + return isMarkdownFile(doc); + } + + if (resolvedHrefPath.scheme === Schemes.notebookCell) { + for (const notebook of vscode.workspace.notebookDocuments) { + for (const cell of notebook.getCells()) { + if (cell.kind === vscode.NotebookCellKind.Markup && isMarkdownFile(cell.document)) { + return true; + } + } + } + return false; + } + return markdownFileExtensions.includes(URI.Utils.extname(resolvedHrefPath).toLowerCase().replace('.', '')); }