diff --git a/apps/vscode/src/lsp/client.ts b/apps/vscode/src/lsp/client.ts index 4dc7d22c..c527b2d1 100644 --- a/apps/vscode/src/lsp/client.ts +++ b/apps/vscode/src/lsp/client.ts @@ -64,6 +64,7 @@ import { getHover, getSignatureHelpHover } from "../core/hover"; import { imageHover } from "../providers/hover-image"; import { LspInitializationOptions, QuartoContext } from "quarto-core"; import { extensionHost } from "../host"; +import semver from "semver"; let client: LanguageClient; @@ -110,11 +111,16 @@ export async function activateLsp( middleware.provideSignatureHelp = embeddedSignatureHelpProvider(engine); } extensionHost().registerStatementRangeProvider(engine); - + // create client options - const initializationOptions : LspInitializationOptions = { + const initializationOptions: LspInitializationOptions = { quartoBinPath: quartoContext.binPath }; + + const documentSelectorPattern = semver.gte(quartoContext.version, "1.6.24") ? + "**/_{brand,quarto,metadata,extension}*.{yml,yaml}" : + "**/_{quarto,metadata,extension}*.{yml,yaml}"; + const clientOptions: LanguageClientOptions = { initializationOptions, documentSelector: [ @@ -122,7 +128,7 @@ export async function activateLsp( { scheme: "*", language: "yaml", - pattern: "**/_{quarto,metadata,extension}*.{yml,yaml}", + pattern: documentSelectorPattern, }, ], middleware, @@ -284,7 +290,7 @@ function embeddedGoToDefinitionProvider(engine: MarkdownEngine) { ); const resolveLocation = (location: Location) => { if (isLanguageVirtualDoc(vdoc.language, location.uri) || - location.uri.toString() === vdocUri.uri.toString()) { + location.uri.toString() === vdocUri.uri.toString()) { return new Location( document.uri, unadjustedRange(vdoc.language, location.range) @@ -295,7 +301,7 @@ function embeddedGoToDefinitionProvider(engine: MarkdownEngine) { }; const resolveLocationLink = (location: LocationLink) => { if (isLanguageVirtualDoc(vdoc.language, location.targetUri) || - location.targetUri.toString() === vdocUri.uri.toString()) { + location.targetUri.toString() === vdocUri.uri.toString()) { const locationLink: LocationLink = { targetRange: unadjustedRange(vdoc.language, location.targetRange), originSelectionRange: location.originSelectionRange diff --git a/packages/quarto-core/src/document.ts b/packages/quarto-core/src/document.ts index fde58122..a0df6ed5 100644 --- a/packages/quarto-core/src/document.ts +++ b/packages/quarto-core/src/document.ts @@ -1,7 +1,7 @@ /* * document.ts * - * Copyright (C) 2023 by Posit Software, PBC + * Copyright (C) 2023-2024 by Posit Software, PBC * Copyright (c) Microsoft Corporation. All rights reserved. * * Unless you have received this program directly from Posit Software pursuant @@ -22,50 +22,50 @@ import { makeRange } from 'quarto-core'; * A document in the workspace. */ export interface Document { - /** - * The uri of the document, as a string. - */ - readonly uri: string; - - /** - * The uri of the document, as a URI. - */ - readonly $uri?: URI; - - /** - * The lanugageId of the document - */ - readonly languageId : string | undefined; - - /** - * Version number of the document's content. - */ - readonly version: number; - - /** - * The total number of lines in the document. - */ - readonly lineCount: number; - - /** - * Get text contents of the document. - * - * @param range Optional range to get the text of. If not specified, the entire document content is returned. - */ - getText(range?: Range): string; - - /** - * Converts an offset in the document into a {@link Position position}. - */ - positionAt(offset: number): Position; + /** + * The uri of the document, as a string. + */ + readonly uri: string; + + /** + * The uri of the document, as a URI. + */ + readonly $uri?: URI; + + /** + * The lanugageId of the document + */ + readonly languageId: string | undefined; + + /** + * Version number of the document's content. + */ + readonly version: number; + + /** + * The total number of lines in the document. + */ + readonly lineCount: number; + + /** + * Get text contents of the document. + * + * @param range Optional range to get the text of. If not specified, the entire document content is returned. + */ + getText(range?: Range): string; + + /** + * Converts an offset in the document into a {@link Position position}. + */ + positionAt(offset: number): Position; } export function getLine(doc: Document, line: number): string { - return doc.getText(makeRange(line, 0, line, Number.MAX_VALUE)).replace(/\r?\n$/, ''); + return doc.getText(makeRange(line, 0, line, Number.MAX_VALUE)).replace(/\r?\n$/, ''); } export function getDocUri(doc: Document): URI { - return doc.$uri ?? URI.parse(doc.uri); + return doc.$uri ?? URI.parse(doc.uri); } @@ -100,6 +100,7 @@ export function isQuartoYaml(doc: Document) { return ( doc.languageId === kYamlLanguageId && (doc.uri.match(/_quarto(-.*?)?\.ya?ml$/) || + doc.uri.match(/_brand\.ya?ml$/) || doc.uri.match(/_metadata\.ya?ml$/) || doc.uri.match(/_extension\.ya?ml$/)) ); @@ -113,7 +114,7 @@ const kRegExYAML = /(^)(---[ \t]*[\r\n]+(?![ \t]*[\r\n]+)[\W\w]*?[\r\n]+(?:---|\.\.\.))([ \t]*)$/gm; export function isQuartoDocWithFormat(doc: Document | string, format: string) { - if (typeof(doc) !== "string") { + if (typeof (doc) !== "string") { if (isQuartoDoc(doc)) { doc = doc.getText(); } else { @@ -125,7 +126,7 @@ export function isQuartoDocWithFormat(doc: Document | string, format: string) { if (match) { const yaml = match[0]; return ( - !!yaml.match(new RegExp("^format:\\s+" + format + "\\s*$","gm")) || + !!yaml.match(new RegExp("^format:\\s+" + format + "\\s*$", "gm")) || !!yaml.match(new RegExp("^[ \\t]*" + format + ":\\s*(default)?\\s*$", "gm")) ); }