Skip to content

Commit

Permalink
create project can open in positron
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv committed Aug 27, 2024
1 parent 8146046 commit 6895daf
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
4 changes: 4 additions & 0 deletions news/changelog-1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/command/create/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
67 changes: 66 additions & 1 deletion src/command/create/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -29,6 +33,7 @@ export interface Editor {
}

export const kEditorInfos: EditorInfo[] = [
positronEditorInfo(),
vscodeEditorInfo(),
rstudioEditorInfo(),
];
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions src/core/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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();
Expand Down

0 comments on commit 6895daf

Please sign in to comment.