From 6895dafe975d3332ed77596f80ca2c3df57587ec Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 27 Aug 2024 15:48:43 +0200 Subject: [PATCH] create project can open in positron --- news/changelog-1.6.md | 4 +++ src/command/create/cmd.ts | 2 +- src/command/create/editor.ts | 67 +++++++++++++++++++++++++++++++++++- src/core/platform.ts | 9 +++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index db56f3d8ea..4838304ab6 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -19,6 +19,10 @@ All changes included in 1.6: - ([#10217](https://github.com/quarto-dev/quarto-cli/issues/10217)): Explicitly compute units for image dimensions in `typst` format when they're not given. - ([#10212](https://github.com/quarto-dev/quarto-cli/issues/10212)): Moves Pandoc variables to the function declaration for the default template. +## Projects + +- ([#10268](https://github.com/quarto-dev/quarto-cli/issues/10268)]): `quarto create` supports opening project in Positron, in addition to VS Code and RStudio IDE. + ## Engines ### `julia` diff --git a/src/command/create/cmd.ts b/src/command/create/cmd.ts index ea5faf7a77..ccaa93af64 100644 --- a/src/command/create/cmd.ts +++ b/src/command/create/cmd.ts @@ -30,7 +30,7 @@ export const createCommand = new Command() .option( "--open [editor:string]", `Open new artifact in this editor (${ - kEditorInfos.map((info) => info.id).join(",") + kEditorInfos.map((info) => info.id).join(", ") })`, ) .option("--no-open", "Do not open in an editor") diff --git a/src/command/create/editor.ts b/src/command/create/editor.ts index 228c74fa56..0b848bd29a 100644 --- a/src/command/create/editor.ts +++ b/src/command/create/editor.ts @@ -7,7 +7,11 @@ import { CreateResult } from "./cmd-types.ts"; import { which } from "../../core/path.ts"; -import { isRStudioTerminal, isVSCodeTerminal } from "../../core/platform.ts"; +import { + isPositronTerminal, + isRStudioTerminal, + isVSCodeTerminal, +} from "../../core/platform.ts"; import { basename, dirname, join } from "../../deno_ral/path.ts"; import { existsSync } from "fs/mod.ts"; @@ -29,6 +33,7 @@ export interface Editor { } export const kEditorInfos: EditorInfo[] = [ + positronEditorInfo(), vscodeEditorInfo(), rstudioEditorInfo(), ]; @@ -141,6 +146,66 @@ function vscodeEditorInfo(): EditorInfo { return editorInfo; } +function positronEditorInfo(): EditorInfo { + const editorInfo: EditorInfo = { + id: "positron", + name: "positron", + open: (path: string, createResult: CreateResult) => { + const artifactPath = createResult.path; + const cwd = Deno.statSync(artifactPath).isDirectory + ? artifactPath + : dirname(artifactPath); + + return async () => { + const p = Deno.run({ + cmd: [path, artifactPath], + cwd, + }); + await p.status(); + }; + }, + inEditor: isPositronTerminal(), + actions: [], + }; + + if (Deno.build.os === "windows") { + editorInfo.actions.push({ + action: "which", + arg: "Positron.exe", + }); + const pathActions = windowsAppPaths("Positron", "Positron.exe").map( + (path) => { + return { + action: "path", + arg: path, + } as ScanAction; + }, + ); + editorInfo.actions.push(...pathActions); + } else if (Deno.build.os === "darwin") { + editorInfo.actions.push({ + action: "which", + arg: "positron", + }); + + const pathActions = macosAppPaths( + "Positron.app/Contents/Resources/app/bin/positron", + ).map((path) => { + return { + action: "path", + arg: path, + } as ScanAction; + }); + editorInfo.actions.push(...pathActions); + } else { + editorInfo.actions.push({ + action: "which", + arg: "positron", + }); + } + return editorInfo; +} + function rstudioEditorInfo(): EditorInfo { const editorInfo: EditorInfo = { id: "rstudio", diff --git a/src/core/platform.ts b/src/core/platform.ts index 5178f14633..74c890d4e4 100644 --- a/src/core/platform.ts +++ b/src/core/platform.ts @@ -24,6 +24,10 @@ export function isRStudio() { return !!Deno.env.get("RSTUDIO"); } +export function isPositron() { + return !!Deno.env.get("POSITRON"); +} + export function isVSCodeOutputChannel() { return !!Deno.env.get("VSCODE_PID"); } @@ -46,6 +50,11 @@ export function isRStudioTerminal() { return !!Deno.env.get("RSTUDIO_TERM"); } +export function isPositronTerminal() { + // it seems there is no POSITRON_TERM variable set + return isPositron(); +} + export function isServerSession() { return isRStudioServer() || isRStudioWorkbench() || isJupyterServer() || isJupyterHubServer() || isVSCodeServer();