Skip to content

Commit 81147b4

Browse files
authored
Fix up some logging (Quarto CLI discovery, extension host warnings) (#878)
* Add some logging for Quarto CLI discovery * Pass resource to `getConfiguration()` to avoid polluting logs * Don't fetch ALL settings, to address warnings in logs * Feedback on logs from @vezwork
1 parent 0857782 commit 81147b4

6 files changed

Lines changed: 170 additions & 43 deletions

File tree

apps/lsp/src/config.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,27 @@ export class ConfigurationManager extends Disposable {
158158

159159
public async update() {
160160
this._logger.logTrace('Sending \'configuration\' request');
161-
const settings = await this.connection_.workspace.getConfiguration();
161+
// Request only the specific sections we need to avoid warnings about
162+
// language-scoped settings like [markdown], [python], etc.
163+
const [workbench, quarto] = await this.connection_.workspace.getConfiguration([
164+
{ section: 'workbench' },
165+
{ section: 'quarto' }
166+
]);
162167

163168
this._settings = {
164169
...defaultSettings(),
165170
workbench: {
166-
colorTheme: settings.workbench.colorTheme
171+
colorTheme: workbench?.colorTheme ?? this._settings.workbench.colorTheme
167172
},
168173
quarto: {
169-
logLevel: Logger.parseLogLevel(settings.quarto.server.logLevel),
170-
path: settings.quarto.path,
174+
logLevel: Logger.parseLogLevel(quarto?.server?.logLevel),
175+
path: quarto?.path ?? this._settings.quarto.path,
171176
mathjax: {
172-
scale: settings.quarto.mathjax.scale,
173-
extensions: settings.quarto.mathjax.extensions
177+
scale: quarto?.mathjax?.scale ?? this._settings.quarto.mathjax.scale,
178+
extensions: quarto?.mathjax?.extensions ?? this._settings.quarto.mathjax.extensions
174179
},
175180
symbols: {
176-
exportToWorkspace: settings.quarto.symbols.exportToWorkspace
181+
exportToWorkspace: quarto?.symbols?.exportToWorkspace ?? this._settings.quarto.symbols.exportToWorkspace
177182
}
178183
}
179184
};

apps/vscode/src/core/quarto.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,50 @@ import * as fs from "node:fs";
1818

1919
import { window, env, workspace, Uri } from "vscode";
2020
import { tryAcquirePositronApi } from "@posit-dev/positron";
21-
import { QuartoContext } from "quarto-core";
21+
import { QuartoContext, QuartoSource } from "quarto-core";
2222
import { activePythonInterpreter, pythonIsCondaEnv, pythonIsVenv } from "./python";
2323
import { isWindows } from "./platform";
2424

2525

2626
import semver from "semver";
2727

2828

29-
export async function configuredQuartoPath() {
29+
/**
30+
* Result of configuredQuartoPath including the path and source.
31+
*/
32+
export interface ConfiguredQuartoPathResult {
33+
path: string;
34+
source: QuartoSource;
35+
}
36+
37+
/**
38+
* Searches for Quarto in VS Code-specific locations (settings, Positron bundled, pip/venv).
39+
*
40+
* @param logger Optional logger for verbose output
41+
* @returns The path and source if found, undefined otherwise
42+
*/
43+
export async function configuredQuartoPath(
44+
logger?: (msg: string) => void
45+
): Promise<ConfiguredQuartoPathResult | undefined> {
3046

3147
const config = workspace.getConfiguration("quarto");
3248

3349
// explicitly configured trumps everything
3450
const quartoPath = config.get("path") as string | undefined;
3551
if (quartoPath) {
36-
return quartoPath;
52+
logger?.(` Checking quarto.path setting: ${quartoPath}`);
53+
return { path: quartoPath, source: "setting" };
54+
} else {
55+
logger?.(" Checking quarto.path setting: not configured");
3756
}
3857

3958
// check if we should use bundled Quarto in Positron
4059
const useBundledQuarto = config.get("useBundledQuartoInPositron", false); // Default is now false
41-
if (useBundledQuarto) {
42-
// Check if we're in Positron
43-
const isPositron = tryAcquirePositronApi();
60+
const isPositron = tryAcquirePositronApi();
4461

62+
if (useBundledQuarto) {
4563
if (isPositron) {
64+
logger?.(" Checking Positron bundled Quarto: enabled");
4665
// Use path relative to the application root for Positron's bundled Quarto
4766
const rootPath = env.appRoot; // Use vscode.env.appRoot as the application root path
4867
const positronQuartoPath = path.join(
@@ -53,9 +72,11 @@ export async function configuredQuartoPath() {
5372
);
5473

5574
if (fs.existsSync(positronQuartoPath)) {
56-
return positronQuartoPath;
75+
logger?.(` Found Positron bundled Quarto at ${positronQuartoPath}`);
76+
return { path: positronQuartoPath, source: "positron-bundled" };
5777
} else {
5878
// Log error when bundled Quarto can't be found
79+
logger?.(` Positron bundled Quarto not found at ${positronQuartoPath}`);
5980
console.error(
6081
`useBundledQuartoInPositron is enabled but bundled Quarto not found at expected path: ${positronQuartoPath}. ` +
6182
`Verify Quarto is bundled in the Positron installation.`
@@ -65,24 +86,40 @@ export async function configuredQuartoPath() {
6586
"Unable to find bundled Quarto in Positron; falling back to system installation"
6687
);
6788
}
89+
} else {
90+
logger?.(" Not running in Positron, skipping bundled Quarto check");
6891
}
92+
} else {
93+
logger?.(` Checking Positron bundled Quarto: disabled (useBundledQuartoInPositron = false)`);
6994
}
7095

7196
// if we can use pip quarto then look for it within the currently python (if its a venv/condaenv)
7297
const usePipQuarto = config.get("usePipQuarto", true);
7398
if (usePipQuarto) {
99+
logger?.(" Checking pip-installed Quarto in Python venv/conda...");
74100
const python = await activePythonInterpreter();
75101
if (python) {
76102
if (pythonIsVenv(python) || pythonIsCondaEnv(python)) {
77103
// check if there is a quarto in the parent directory
78104
const binDir = path.dirname(python);
79105
const quartoPath = path.join(binDir, isWindows() ? "quarto.exe" : "quarto");
80106
if (fs.existsSync(quartoPath)) {
81-
return quartoPath;
107+
logger?.(` Found pip-installed Quarto at ${quartoPath}`);
108+
return { path: quartoPath, source: "pip-venv" };
109+
} else {
110+
logger?.(` No Quarto found in Python environment at ${binDir}`);
82111
}
112+
} else {
113+
logger?.(" Active Python is not in a venv or conda environment");
83114
}
115+
} else {
116+
logger?.(" No active Python interpreter found");
84117
}
118+
} else {
119+
logger?.(" Checking pip-installed Quarto: disabled (usePipQuarto = false)");
85120
}
121+
122+
return undefined;
86123
}
87124

88125

apps/vscode/src/main.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { activateEditor } from "./providers/editor/editor";
3232
import { activateCopyFiles } from "./providers/copyfiles";
3333
import { activateZotero } from "./providers/zotero/zotero";
3434
import { extensionHost } from "./host";
35-
import { initQuartoContext } from "quarto-core";
35+
import { initQuartoContext, getSourceDescription } from "quarto-core";
3636
import { configuredQuartoPath } from "./core/quarto";
3737
import { activateDenoConfig } from "./providers/deno-config";
3838
import { textFormattingCommands } from "./providers/text-format";
@@ -64,17 +64,30 @@ export async function activate(context: vscode.ExtensionContext) {
6464
const commands = cellCommands(host, engine);
6565

6666
// get quarto context (some features conditional on it)
67-
const quartoPath = await configuredQuartoPath();
67+
// Create a logger function for verbose discovery output
68+
const discoveryLogger = (msg: string) => outputChannel.info(msg);
69+
70+
outputChannel.info("Searching for Quarto CLI...");
71+
const quartoPathResult = await configuredQuartoPath(discoveryLogger);
6872
const workspaceFolder = vscode.workspace.workspaceFolders?.length
6973
? vscode.workspace.workspaceFolders[0].uri.fsPath
7074
: undefined;
7175
const quartoContext = initQuartoContext(
72-
quartoPath,
76+
quartoPathResult?.path,
7377
workspaceFolder,
7478
// Look for quarto in the app root; this is where Positron installs it
7579
[path.join(vscode.env.appRoot, "quarto", "bin")],
76-
vscode.window.showWarningMessage
80+
vscode.window.showWarningMessage,
81+
{ logger: discoveryLogger, source: quartoPathResult?.source }
7782
);
83+
84+
// Log the final discovery result
85+
if (quartoContext.available) {
86+
const sourceDescription = getSourceDescription(quartoContext.source);
87+
outputChannel.info(`Using Quarto ${quartoContext.version} from ${quartoContext.binPath}${sourceDescription}`);
88+
} else {
89+
outputChannel.info("Quarto CLI not found. Some features will be unavailable.");
90+
}
7891
if (quartoContext.available) {
7992

8093
// enable commands conditional on quarto installation

apps/vscode/src/providers/copyfiles/filename.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function getNewFileName(document: vscode.TextDocument, file: vscode
4141

4242
function getDesiredNewFilePath(document: vscode.TextDocument, file: vscode.DataTransferFile): vscode.Uri {
4343
const docUri = getParentDocumentUri(document);
44-
const config = vscode.workspace.getConfiguration('markdown').get<Record<string, string>>('experimental.copyFiles.destination') ?? {};
44+
const config = vscode.workspace.getConfiguration('markdown', docUri).get<Record<string, string>>('experimental.copyFiles.destination') ?? {};
4545
for (const [rawGlob, rawDest] of Object.entries(config)) {
4646
for (const glob of parseGlob(rawGlob)) {
4747
if (picomatch.isMatch(docUri.path, glob)) {

apps/vscode/src/providers/deno-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function activateDenoConfig(context: ExtensionContext, engine: MarkdownEn
2424
if (extensions.getExtension("denoland.vscode-deno")) {
2525
const ensureDenoConfig = async (doc: TextDocument) => {
2626
if (isQuartoDoc(doc)) {
27-
const config = workspace.getConfiguration();
27+
const config = workspace.getConfiguration(undefined, doc.uri);
2828
const inspectDenoEnable = config.inspect("deno.enable");
2929
if (
3030
!inspectDenoEnable?.globalValue &&

0 commit comments

Comments
 (0)