@@ -18,31 +18,50 @@ import * as fs from "node:fs";
1818
1919import { window , env , workspace , Uri } from "vscode" ;
2020import { tryAcquirePositronApi } from "@posit-dev/positron" ;
21- import { QuartoContext } from "quarto-core" ;
21+ import { QuartoContext , QuartoSource } from "quarto-core" ;
2222import { activePythonInterpreter , pythonIsCondaEnv , pythonIsVenv } from "./python" ;
2323import { isWindows } from "./platform" ;
2424
2525
2626import 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
0 commit comments