From 7a10a26be66552ac5bff6d0edb11ffc6684006f9 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Mon, 28 Oct 2024 09:50:40 -0600 Subject: [PATCH 1/3] Apply default formatting to `.ts` files --- apps/vscode/src/@types/hooks.d.ts | 6 +- apps/vscode/src/core/config.ts | 2 +- apps/vscode/src/core/doc.ts | 2 +- apps/vscode/src/core/platform.ts | 4 +- apps/vscode/src/core/quarto.ts | 4 +- apps/vscode/src/core/schemes.ts | 2 +- apps/vscode/src/core/terminal.ts | 18 +- apps/vscode/src/core/workspace.ts | 12 +- apps/vscode/src/host/executors.ts | 10 +- apps/vscode/src/host/hooks.ts | 80 ++++----- apps/vscode/src/host/index.ts | 22 +-- apps/vscode/src/host/preview.ts | 6 +- apps/vscode/src/main.ts | 4 +- apps/vscode/src/markdown/engine.ts | 10 +- apps/vscode/src/providers/assist/codelens.ts | 4 +- apps/vscode/src/providers/assist/commands.ts | 6 +- .../src/providers/assist/render-assist.ts | 28 +-- .../src/providers/assist/render-cache.ts | 2 +- apps/vscode/src/providers/assist/webview.ts | 38 ++-- apps/vscode/src/providers/background.ts | 8 +- apps/vscode/src/providers/cell/codelens.ts | 4 +- apps/vscode/src/providers/cell/commands.ts | 100 +++++------ apps/vscode/src/providers/cell/executors.ts | 26 +-- apps/vscode/src/providers/cell/options.ts | 4 +- .../src/providers/create/create-project.ts | 2 +- apps/vscode/src/providers/create/create.ts | 2 +- apps/vscode/src/providers/deno-config.ts | 2 +- apps/vscode/src/providers/diagram/codelens.ts | 4 +- apps/vscode/src/providers/diagram/commands.ts | 8 +- .../src/providers/diagram/diagram-webview.ts | 12 +- apps/vscode/src/providers/diagram/diagram.ts | 6 +- apps/vscode/src/providers/editor/codeview.ts | 92 +++++----- .../vscode/src/providers/editor/connection.ts | 30 ++-- apps/vscode/src/providers/editor/editor.ts | 168 +++++++++--------- apps/vscode/src/providers/editor/images.ts | 20 +-- apps/vscode/src/providers/editor/prefs.ts | 46 ++--- apps/vscode/src/providers/editor/sync.ts | 20 +-- apps/vscode/src/providers/editor/toggle.ts | 18 +- apps/vscode/src/providers/format.ts | 4 +- apps/vscode/src/providers/insert.ts | 2 +- apps/vscode/src/providers/lua-types.ts | 4 +- apps/vscode/src/providers/option.ts | 2 +- apps/vscode/src/providers/preview/commands.ts | 19 +- .../src/providers/preview/preview-env.ts | 10 +- .../src/providers/preview/preview-util.ts | 4 +- .../src/providers/preview/preview-webview.ts | 2 +- apps/vscode/src/providers/render.ts | 73 ++++---- apps/vscode/src/providers/text-format.ts | 2 +- apps/vscode/src/providers/walkthrough.ts | 4 +- apps/vscode/src/providers/webview.ts | 9 +- apps/vscode/src/providers/zotero/zotero.ts | 100 ++++++----- apps/vscode/src/vdoc/languages.ts | 4 +- apps/vscode/src/vdoc/vdoc-completion.ts | 6 +- apps/vscode/src/vdoc/vdoc-content.ts | 5 +- apps/vscode/src/vdoc/vdoc-tempfile.ts | 6 +- apps/vscode/src/vdoc/vdoc.ts | 32 ++-- 56 files changed, 557 insertions(+), 563 deletions(-) diff --git a/apps/vscode/src/@types/hooks.d.ts b/apps/vscode/src/@types/hooks.d.ts index f971d084..99ae993e 100644 --- a/apps/vscode/src/@types/hooks.d.ts +++ b/apps/vscode/src/@types/hooks.d.ts @@ -42,9 +42,9 @@ declare module 'positron' { export interface PositronWindow { createPreviewPanel( - viewType: string, - title: string, - preserveFocus?: boolean, + viewType: string, + title: string, + preserveFocus?: boolean, options?: PreviewOptions ): PreviewPanel; } diff --git a/apps/vscode/src/core/config.ts b/apps/vscode/src/core/config.ts index 95d2046f..bf89a409 100644 --- a/apps/vscode/src/core/config.ts +++ b/apps/vscode/src/core/config.ts @@ -18,7 +18,7 @@ export async function safeUpdateConfig(updateFn: () => Promise) { try { await updateFn(); - } catch(error) { + } catch (error) { // if the user's settings.json file is corrupt/invalid this // will throw an exception and prevent loading of the extension console.log("Unexpected error writing config (settings.json may be corrupt)"); diff --git a/apps/vscode/src/core/doc.ts b/apps/vscode/src/core/doc.ts index ba2b3986..1ad3cf72 100644 --- a/apps/vscode/src/core/doc.ts +++ b/apps/vscode/src/core/doc.ts @@ -124,7 +124,7 @@ export function quartoCanRenderMarkdown(document: vscode.TextDocument) { export function quartoCanRenderScript(document: vscode.TextDocument) { const text = document.getText(); return isJupyterPercentScript(document.uri.fsPath, text) || - isKnitrSpinScript(document.uri.fsPath, text); + isKnitrSpinScript(document.uri.fsPath, text); } export function validatateQuartoCanRender(document: vscode.TextDocument) { diff --git a/apps/vscode/src/core/platform.ts b/apps/vscode/src/core/platform.ts index 8a1922c0..ebfe8e67 100644 --- a/apps/vscode/src/core/platform.ts +++ b/apps/vscode/src/core/platform.ts @@ -66,11 +66,11 @@ export function vsCodeWebUrl(serverUrl: string) { return rswURL(port); } else if (isVSCodeServer()) { return vsCodeServerProxyUri()!.replace("{{port}}", `${port}`); - } + } } // default to reflecting back serverUrl return serverUrl; - + } export function rswURL(port: string) { diff --git a/apps/vscode/src/core/quarto.ts b/apps/vscode/src/core/quarto.ts index 96a34b68..4bf249d1 100644 --- a/apps/vscode/src/core/quarto.ts +++ b/apps/vscode/src/core/quarto.ts @@ -28,13 +28,13 @@ import semver from "semver"; export async function configuredQuartoPath() { const config = workspace.getConfiguration("quarto"); - + // explicitly configured trumps everything const quartoPath = config.get("path") as string | undefined; if (quartoPath) { return quartoPath; } - + // if we can use pip quarto then look for it within the currently python (if its a venv/condaenv) const usePipQuarto = config.get("usePipQuarto", true); if (usePipQuarto) { diff --git a/apps/vscode/src/core/schemes.ts b/apps/vscode/src/core/schemes.ts index 29fadb17..8f394cad 100644 --- a/apps/vscode/src/core/schemes.ts +++ b/apps/vscode/src/core/schemes.ts @@ -33,5 +33,5 @@ export function hasFileScheme(uri: Uri) { } export function isOfScheme(scheme: string, link: string): boolean { - return link.toLowerCase().startsWith(scheme + ':'); + return link.toLowerCase().startsWith(scheme + ':'); } diff --git a/apps/vscode/src/core/terminal.ts b/apps/vscode/src/core/terminal.ts index 11687871..997d2887 100644 --- a/apps/vscode/src/core/terminal.ts +++ b/apps/vscode/src/core/terminal.ts @@ -33,7 +33,7 @@ export interface TerminalEnv { QUARTO_R?: string; } -export async function terminalEnv(uri?: Uri) : Promise { +export async function terminalEnv(uri?: Uri): Promise { const env: TerminalEnv = {}; @@ -119,17 +119,17 @@ export function terminalCommand(command: string, context: QuartoContext, target? } export async function sendTerminalCommand( - terminal: Terminal, - terminalEnv: TerminalEnv, - context: QuartoContext, + terminal: Terminal, + terminalEnv: TerminalEnv, + context: QuartoContext, cmd: string[] ) { - + // create cmd text const cmdText = context.useCmd - ? `cmd /C"${cmd.join(" ")}"` - : cmd.join(" "); - + ? `cmd /C"${cmd.join(" ")}"` + : cmd.join(" "); + // show the terminal terminal.show(true); @@ -165,7 +165,7 @@ export async function killTerminal(name: string, before?: () => Promise) { } -function requiredTerminalDelay(env?: TerminalEnv) : number { +function requiredTerminalDelay(env?: TerminalEnv): number { try { if (env?.QUARTO_PYTHON) { if (pythonIsVenv(env.QUARTO_PYTHON)) { diff --git a/apps/vscode/src/core/workspace.ts b/apps/vscode/src/core/workspace.ts index 90094045..dc8ad8fd 100644 --- a/apps/vscode/src/core/workspace.ts +++ b/apps/vscode/src/core/workspace.ts @@ -15,11 +15,11 @@ import { workspace, WorkspaceFolder, Uri } from "vscode"; -export function activeWorkspaceFolder(uri?: Uri) : WorkspaceFolder | undefined { - const workspaceFolder = uri - ? workspace.getWorkspaceFolder(uri) - : workspace.workspaceFolders?.length - ? workspace.workspaceFolders[0] - : undefined; +export function activeWorkspaceFolder(uri?: Uri): WorkspaceFolder | undefined { + const workspaceFolder = uri + ? workspace.getWorkspaceFolder(uri) + : workspace.workspaceFolders?.length + ? workspace.workspaceFolders[0] + : undefined; return workspaceFolder; } \ No newline at end of file diff --git a/apps/vscode/src/host/executors.ts b/apps/vscode/src/host/executors.ts index 7f749f63..0fa1a570 100644 --- a/apps/vscode/src/host/executors.ts +++ b/apps/vscode/src/host/executors.ts @@ -55,7 +55,7 @@ interface VSCodeCellExecutor extends CellExecutor { executeSelection?: () => Promise; } -const jupyterCellExecutor = (language: string) : VSCodeCellExecutor => ({ +const jupyterCellExecutor = (language: string): VSCodeCellExecutor => ({ language, requiredExtension: ["ms-toolsai.jupyter"], requiredExtensionName: "Jupyter", @@ -179,16 +179,16 @@ export function isDenoDocument( if (jupyterOption) { if (jupyterOption === "deno") { return true; - } else if (typeof(jupyterOption) === "object") { - const kernelspec = (jupyterOption as Record)["kernelspec"]; - if (typeof(kernelspec) === "object") { + } else if (typeof (jupyterOption) === "object") { + const kernelspec = (jupyterOption as Record)["kernelspec"]; + if (typeof (kernelspec) === "object") { return (kernelspec as JupyterKernelspec).name === "deno"; } } else { return false; } } - + // another explicit declaration of engine that isn't jupyter if (engineOption && engineOption !== "jupyter") { return false; diff --git a/apps/vscode/src/host/hooks.ts b/apps/vscode/src/host/hooks.ts index 91aa8946..c892adf2 100644 --- a/apps/vscode/src/host/hooks.ts +++ b/apps/vscode/src/host/hooks.ts @@ -23,12 +23,12 @@ import { MarkdownEngine } from '../markdown/engine'; import { virtualDoc, virtualDocUri, adjustedPosition } from "../vdoc/vdoc"; declare global { - function acquirePositronApi() : hooks.PositronApi; + function acquirePositronApi(): hooks.PositronApi; } -let api : hooks.PositronApi | null | undefined; +let api: hooks.PositronApi | null | undefined; -export function hooksApi() : hooks.PositronApi | null { +export function hooksApi(): hooks.PositronApi | null { if (api === undefined) { try { api = acquirePositronApi(); @@ -43,20 +43,20 @@ export function hasHooks() { return !!hooksApi(); } -export function hooksExtensionHost() : ExtensionHost { +export function hooksExtensionHost(): ExtensionHost { return { // supported executable languages (we delegate to the default for langugaes // w/o runtimes so we support all languages) executableLanguages, - cellExecutorForLanguage: async (language: string, document: vscode.TextDocument, engine: MarkdownEngine, silent?: boolean) + cellExecutorForLanguage: async (language: string, document: vscode.TextDocument, engine: MarkdownEngine, silent?: boolean) : Promise => { - switch(language) { + switch (language) { // use hooks for known runtimes case "python": case "r": return { - execute: async (blocks: string[], _editorUri?: vscode.Uri) : Promise => { + execute: async (blocks: string[], _editorUri?: vscode.Uri): Promise => { const runtime = hooksApi()?.runtime; if (runtime === undefined) { @@ -68,7 +68,7 @@ export function hooksExtensionHost() : ExtensionHost { language = "r"; blocks = blocks.map(pythonWithReticulate); } - + // Our callback executes each block sequentially const callback = async () => { for (const block of blocks) { @@ -78,9 +78,9 @@ export function hooksExtensionHost() : ExtensionHost { await ExecuteQueue.instance.add(language, callback); }, - executeSelection: async () : Promise => { - await vscode.commands.executeCommand('workbench.action.positronConsole.executeCode', {languageId: language}); - } + executeSelection: async (): Promise => { + await vscode.commands.executeCommand('workbench.action.positronConsole.executeCode', { languageId: language }); + } }; // delegate for other languages @@ -92,16 +92,16 @@ export function hooksExtensionHost() : ExtensionHost { registerStatementRangeProvider: (engine: MarkdownEngine): vscode.Disposable => { const hooks = hooksApi(); if (hooks) { - return hooks.languages.registerStatementRangeProvider('quarto', + return hooks.languages.registerStatementRangeProvider('quarto', new EmbeddedStatementRangeProvider(engine)); } - return new vscode.Disposable(() => {}); + return new vscode.Disposable(() => { }); }, createPreviewPanel: ( - viewType: string, + viewType: string, title: string, - preserveFocus?: boolean, + preserveFocus?: boolean, options?: vscode.WebviewPanelOptions & vscode.WebviewOptions ): HostWebviewPanel => { @@ -117,7 +117,7 @@ export function hooksExtensionHost() : ExtensionHost { portMapping: options?.portMapping } )!; - + // adapt to host interface return new HookWebviewPanel(panel); } @@ -126,7 +126,7 @@ export function hooksExtensionHost() : ExtensionHost { class HookWebviewPanel implements HostWebviewPanel { - constructor(private readonly panel_: hooks.PreviewPanel) {} + constructor(private readonly panel_: hooks.PreviewPanel) { } get webview() { return this.panel_.webview; }; get visible() { return this.panel_.visible; }; @@ -139,34 +139,34 @@ class HookWebviewPanel implements HostWebviewPanel { } class EmbeddedStatementRangeProvider implements HostStatementRangeProvider { - private readonly _engine: MarkdownEngine; + private readonly _engine: MarkdownEngine; - constructor( - readonly engine: MarkdownEngine, - ) { - this._engine = engine; - } + constructor( + readonly engine: MarkdownEngine, + ) { + this._engine = engine; + } async provideStatementRange( - document: vscode.TextDocument, - position: vscode.Position, - token: vscode.CancellationToken): Promise { - const vdoc = await virtualDoc(document, position, this._engine); - if (vdoc) { - const vdocUri = await virtualDocUri(vdoc, document.uri, "statementRange"); - try { - return getStatementRange(vdocUri.uri, adjustedPosition(vdoc.language, position)); - } catch (error) { - return undefined; - } finally { - if (vdocUri.cleanup) { - await vdocUri.cleanup(); - } - } - } else { + document: vscode.TextDocument, + position: vscode.Position, + token: vscode.CancellationToken): Promise { + const vdoc = await virtualDoc(document, position, this._engine); + if (vdoc) { + const vdocUri = await virtualDocUri(vdoc, document.uri, "statementRange"); + try { + return getStatementRange(vdocUri.uri, adjustedPosition(vdoc.language, position)); + } catch (error) { return undefined; + } finally { + if (vdocUri.cleanup) { + await vdocUri.cleanup(); + } } - }; + } else { + return undefined; + } + }; } async function getStatementRange( diff --git a/apps/vscode/src/host/index.ts b/apps/vscode/src/host/index.ts index 951e8d4d..0f8295de 100644 --- a/apps/vscode/src/host/index.ts +++ b/apps/vscode/src/host/index.ts @@ -24,7 +24,7 @@ import { TextDocument } from "vscode"; import { MarkdownEngine } from "../markdown/engine"; export type { CellExecutor }; -export type { EditorToolbarProvider, ToolbarItem, ToolbarCommand, ToolbarButton, ToolbarMenu } from './toolbar'; +export type { EditorToolbarProvider, ToolbarItem, ToolbarCommand, ToolbarButton, ToolbarMenu } from './toolbar'; export interface HostWebviewPanel extends vscode.Disposable { readonly webview: vscode.Webview; @@ -50,13 +50,13 @@ export interface HostStatementRange { export interface ExtensionHost { // code execution - executableLanguages(visualMode: boolean, document: TextDocument, engine: MarkdownEngine) : string[]; + executableLanguages(visualMode: boolean, document: TextDocument, engine: MarkdownEngine): string[]; cellExecutorForLanguage( - language: string, + language: string, document: TextDocument, engine: MarkdownEngine, silent?: boolean - ) : Promise; + ): Promise; // statement range provider registerStatementRangeProvider( @@ -65,21 +65,21 @@ export interface ExtensionHost { // preview createPreviewPanel( - viewType: string, + viewType: string, title: string, - preserveFocus?: boolean, + preserveFocus?: boolean, options?: WebviewPanelOptions & WebviewOptions ): HostWebviewPanel; // editor toolbar registerEditorToolbarProvider?( - selector: DocumentSelector, + selector: DocumentSelector, provider: EditorToolbarProvider ): Disposable; } -export function extensionHost() : ExtensionHost { +export function extensionHost(): ExtensionHost { if (hasHooks()) { return hooksExtensionHost(); } else { @@ -87,10 +87,10 @@ export function extensionHost() : ExtensionHost { } } -function defaultExtensionHost() : ExtensionHost { +function defaultExtensionHost(): ExtensionHost { return { executableLanguages: (visualMode: boolean, document: TextDocument, engine: MarkdownEngine) => { - + const languages = executableLanguages(); const knitr = isKnitrDocument(document, engine); @@ -101,7 +101,7 @@ function defaultExtensionHost() : ExtensionHost { cellExecutorForLanguage, // in the default extension host, this is a noop: registerStatementRangeProvider: (engine: MarkdownEngine): vscode.Disposable => { - return new vscode.Disposable(() => {}); + return new vscode.Disposable(() => { }); }, createPreviewPanel, }; diff --git a/apps/vscode/src/host/preview.ts b/apps/vscode/src/host/preview.ts index 9850ef92..fd81df5b 100644 --- a/apps/vscode/src/host/preview.ts +++ b/apps/vscode/src/host/preview.ts @@ -13,12 +13,12 @@ * */ -import { window, WebviewPanel, WebviewOptions, WebviewPanelOptions, ViewColumn} from "vscode"; +import { window, WebviewPanel, WebviewOptions, WebviewPanelOptions, ViewColumn } from "vscode"; export function createPreviewPanel( - viewType: string, + viewType: string, title: string, - preserveFocus?: boolean, + preserveFocus?: boolean, options?: WebviewPanelOptions & WebviewOptions ): WebviewPanel { return window.createWebviewPanel( diff --git a/apps/vscode/src/main.ts b/apps/vscode/src/main.ts index c9195e58..4371c4e5 100644 --- a/apps/vscode/src/main.ts +++ b/apps/vscode/src/main.ts @@ -37,7 +37,7 @@ import { configuredQuartoPath } from "./core/quarto"; import { activateDenoConfig } from "./providers/deno-config"; export async function activate(context: vscode.ExtensionContext) { - + // create extension host const host = extensionHost(); @@ -129,5 +129,5 @@ export async function activate(context: vscode.ExtensionContext) { export async function deactivate() { return deactivateLsp(); -} +} diff --git a/apps/vscode/src/markdown/engine.ts b/apps/vscode/src/markdown/engine.ts index 94d1c9ee..82912207 100644 --- a/apps/vscode/src/markdown/engine.ts +++ b/apps/vscode/src/markdown/engine.ts @@ -19,7 +19,7 @@ import { Parser, Document, QuartoContext, Token, markdownitParser } from "quarto import { Range, Position } from "vscode-languageserver-types"; export class MarkdownEngine { - + private readonly parser_: Parser; public constructor() { @@ -35,9 +35,9 @@ export class MarkdownEngine { get lineCount() { return document.lineCount; }, getText(range?: Range | undefined): string { const r = range ? new vscode.Range( - range.start.line, - range.start.character, - range.end.line, + range.start.line, + range.start.character, + range.end.line, range.end.character ) : undefined; return document.getText(r); @@ -49,5 +49,5 @@ export class MarkdownEngine { return this.parser_(doc); } - + } diff --git a/apps/vscode/src/providers/assist/codelens.ts b/apps/vscode/src/providers/assist/codelens.ts index 657ad2c1..4d58f0d1 100644 --- a/apps/vscode/src/providers/assist/codelens.ts +++ b/apps/vscode/src/providers/assist/codelens.ts @@ -42,7 +42,7 @@ export function quartoLensCodeLensProvider( } const block = mathBlocks[i]; - + // push code lens const range = new Range(block.range.start.line, 0, block.range.start.line, 0); lenses.push( @@ -55,7 +55,7 @@ export function quartoLensCodeLensProvider( }), ] ); - + } return lenses; }, diff --git a/apps/vscode/src/providers/assist/commands.ts b/apps/vscode/src/providers/assist/commands.ts index 92f9e85a..07ed689b 100644 --- a/apps/vscode/src/providers/assist/commands.ts +++ b/apps/vscode/src/providers/assist/commands.ts @@ -28,7 +28,7 @@ export class PreviewMathCommand implements Command { constructor( private readonly provider_: QuartoAssistViewProvider, private readonly engine_: MarkdownEngine - ) {} + ) { } async execute(line: number): Promise { if (window.activeTextEditor) { const doc = window.activeTextEditor.document; @@ -59,7 +59,7 @@ export class PreviewMathCommand implements Command { export class ShowAssistCommand implements Command { private static readonly id = "quarto.showAssist"; public readonly id = ShowAssistCommand.id; - constructor(private readonly provider_: QuartoAssistViewProvider) {} + constructor(private readonly provider_: QuartoAssistViewProvider) { } async execute(): Promise { activateAssistPanel(this.provider_); } @@ -69,7 +69,7 @@ export class ShowAssistCommand implements Command { export class CodeViewAssistCommand implements Command { private static readonly id = "quarto.codeViewAssist"; public readonly id = CodeViewAssistCommand.id; - constructor(private readonly provider_: QuartoAssistViewProvider) {} + constructor(private readonly provider_: QuartoAssistViewProvider) { } async execute(context: CodeViewCellContext, lspRequest: JsonRpcRequestTransport): Promise { this.provider_.codeViewAssist(context, lspRequest); } diff --git a/apps/vscode/src/providers/assist/render-assist.ts b/apps/vscode/src/providers/assist/render-assist.ts index 9c0cce30..21b918ec 100644 --- a/apps/vscode/src/providers/assist/render-assist.ts +++ b/apps/vscode/src/providers/assist/render-assist.ts @@ -91,30 +91,30 @@ export async function renderCodeViewAssist( const hover = (await lspRequest(kCodeViewAssist, [context])) as LspHover | undefined; if (hover) { const contents = [new MarkdownString((hover.contents as MarkupContent).value)]; - const range = hover.range + const range = hover.range ? new Range( - hover.range.start.line, - hover.range.start.character, - hover.range.end.line, - hover.range.end.character - ) + hover.range.start.line, + hover.range.start.character, + hover.range.end.line, + hover.range.end.character + ) : undefined; const assist = getAssistFromHovers([{ contents, range }], asWebviewUri); if (assist) { return assist; } - } + } return undefined; - + } else { const language = embeddedLanguage(context.language); if (language) { - const vdoc = virtualDocForCode(context.code, language); + const vdoc = virtualDocForCode(context.code, language); const vdocUri = await virtualDocUri(vdoc, Uri.file(context.filepath), "hover"); return await withVirtualDocUri(vdocUri, async () => { try { const position = new Position(context.selection.start.line, context.selection.start.character); - + // check for hover const hover = await getHover(vdocUri, language, position); if (hover) { @@ -123,7 +123,7 @@ export async function renderCodeViewAssist( return assist; } } - + if (token.isCancellationRequested) { return undefined; } @@ -136,16 +136,16 @@ export async function renderCodeViewAssist( } catch (error) { console.error(error); } - + return undefined; - + }); } else { return undefined; } } - + } export async function renderActiveAssist( diff --git a/apps/vscode/src/providers/assist/render-cache.ts b/apps/vscode/src/providers/assist/render-cache.ts index 7c2b0dfc..699f3e32 100644 --- a/apps/vscode/src/providers/assist/render-cache.ts +++ b/apps/vscode/src/providers/assist/render-cache.ts @@ -61,7 +61,7 @@ export class EditorRenderCacheKey { public readonly url: Uri, public readonly version: number, public readonly wordRange: Range | undefined - ) {} + ) { } public equals(other: EditorRenderCacheKey): boolean { if (this.url.toString() !== other.url.toString()) { diff --git a/apps/vscode/src/providers/assist/webview.ts b/apps/vscode/src/providers/assist/webview.ts index f818ae01..814c9336 100644 --- a/apps/vscode/src/providers/assist/webview.ts +++ b/apps/vscode/src/providers/assist/webview.ts @@ -48,8 +48,7 @@ enum UpdateMode { } export class QuartoAssistViewProvider - implements WebviewViewProvider, Disposable -{ + implements WebviewViewProvider, Disposable { public static readonly viewType = "quarto-assist"; constructor(context: ExtensionContext) { @@ -132,7 +131,7 @@ export class QuartoAssistViewProvider this.render(true, async ( asWebviewUri: (uri: Uri) => Uri, token: CancellationToken - ) : Promise => { + ): Promise => { return renderCodeViewAssist(context, lspRequest, asWebviewUri, token); }); } @@ -169,11 +168,11 @@ export class QuartoAssistViewProvider } private async render(ignoreCache = false, renderFn = renderActiveAssist) { - + if (!this.shouldRender()) { return; } - + // don't render if the editor state hasn't changed (i.e. the cursor // isn't on a new word range) const newRenderCacheKey = createRenderCacheKey(window.activeTextEditor); @@ -220,9 +219,8 @@ export class QuartoAssistViewProvider if (this.view_) { this.view_.webview.postMessage({ type: "update", - body: `
${ - assist.html - }
`, + body: `
${assist.html + }
`, updateMode: this.updateMode_, }); this.view_.title = assist.type; @@ -260,18 +258,18 @@ export class QuartoAssistViewProvider private shouldRender() { // ignore if we have no view if (!this.view_) { - return false; - } - - // ignore if we are pinned - else if (this.pinned_) { - return false ; - } - - else { - return true; - } - } + return false; + } + + // ignore if we are pinned + else if (this.pinned_) { + return false; + } + + else { + return true; + } + } private updateConfiguration() { diff --git a/apps/vscode/src/providers/background.ts b/apps/vscode/src/providers/background.ts index 5fb49d9a..2aae39d7 100644 --- a/apps/vscode/src/providers/background.ts +++ b/apps/vscode/src/providers/background.ts @@ -69,7 +69,7 @@ export function activateBackgroundHighlighter( // update highlighting on changes to the document (if its visible) vscode.workspace.onDidChangeTextDocument( (event) => { - const visibleEditor = vscode.window.visibleTextEditors.find(editor => { + const visibleEditor = vscode.window.visibleTextEditors.find(editor => { return editor.document.uri.toString() === event.document.uri.toString(); }); if (visibleEditor) { @@ -155,7 +155,7 @@ async function setEditorHighlightDecorations( const inlineRanges: vscode.Range[] = []; if (highlightingConfig.enabled()) { - + // find code blocks const tokens = engine.parse(editor.document); for (const block of tokens.filter(isExecutableLanguageBlock)) { @@ -163,7 +163,7 @@ async function setEditorHighlightDecorations( } // find inline executable code - for (let i=0; i { @@ -116,7 +116,7 @@ abstract class RunCommand { } } - + } protected includeFence() { @@ -130,7 +130,7 @@ abstract class RunCommand { protected abstract doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise; + ): Promise; protected abstract doExecute( editor: TextEditor, @@ -175,7 +175,7 @@ class RunCurrentCellCommand extends RunCommand implements Command { override async doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise { + ): Promise { const activeBlock = context.blocks.find(block => block.active); if (activeBlock) { const executor = await this.cellExecutorForLanguage(activeBlock.language, editor.document, this.engine_); @@ -204,7 +204,7 @@ class RunNextCellCommand extends RunCommand implements Command { override async doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise { + ): Promise { const activeBlockIndex = context.blocks.findIndex(block => block.active); const nextBlock = context.blocks[activeBlockIndex + 1]; if (nextBlock) { @@ -239,7 +239,7 @@ class RunPreviousCellCommand extends RunCommand implements Command { override async doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise { + ): Promise { const activeBlockIndex = context.blocks.findIndex(block => block.active); const prevBlock = context.blocks[activeBlockIndex - 1]; if (prevBlock) { @@ -258,15 +258,15 @@ class RunPreviousCellCommand extends RunCommand implements Command { class RunCurrentCommand extends RunCommand implements Command { constructor( - host: ExtensionHost, - engine: MarkdownEngine, + host: ExtensionHost, + engine: MarkdownEngine, private readonly runSelection_ = false ) { super(host, engine); } public readonly id: string = "quarto.runCurrent"; - + override includeFence() { return false; } @@ -284,7 +284,7 @@ class RunCurrentCommand extends RunCommand implements Command { // if the selection is empty and this isn't a knitr document then it resolves to run cell if (editor.selection.isEmpty && !isKnitrDocument(editor.document, this.engine_) && !this.runSelection_) { - + const code = codeWithoutOptionsFromBlock(block); await executeInteractive(executor, [code], editor.document); @@ -299,14 +299,14 @@ class RunCurrentCommand extends RunCommand implements Command { // take the selected text exactly const selection = editor.selection.isEmpty ? editor.document.getText( - new Range( - new Position(editor.selection.start.line, 0), - new Position( - editor.selection.end.line, - editor.document.lineAt(editor.selection.end).text.length - ) + new Range( + new Position(editor.selection.start.line, 0), + new Position( + editor.selection.end.line, + editor.document.lineAt(editor.selection.end).text.length ) ) + ) : editor.document.getText(editor.selection); // for empty selections we advance to the next line @@ -325,7 +325,7 @@ class RunCurrentCommand extends RunCommand implements Command { override async doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise { + ): Promise { // get selection and active block let selection = context.selectedText; const activeBlock = context.blocks.find(block => block.active); @@ -354,7 +354,7 @@ class RunCurrentCommand extends RunCommand implements Command { const executor = await this.cellExecutorForLanguage(context.activeLanguage, editor.document, this.engine_); if (executor) { await executeInteractive(executor, [selection], editor.document); - + // advance cursor if necessary if (action) { editor.setBlockSelection(context, "nextline"); @@ -400,11 +400,11 @@ class RunCurrentAdvanceCommand extends RunCommand implements Command { override async doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise { + ): Promise { const activeBlock = context.blocks.find(block => block.active); if (activeBlock) { const executor = await this.cellExecutorForLanguage(activeBlock.language, editor.document, this.engine_); - if (executor) { + if (executor) { await executeInteractive(executor, [activeBlock.code], editor.document); const blockContext = await editor.getActiveBlockContext(); if (blockContext) { @@ -466,11 +466,11 @@ class RunCellsAboveCommand extends RunCommand implements Command { } } } - + override async doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise { + ): Promise { const executor = await this.cellExecutorForLanguage(context.activeLanguage, editor.document, this.engine_); if (executor) { const code: string[] = []; @@ -538,7 +538,7 @@ class RunCellsBelowCommand extends RunCommand implements Command { override async doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise { + ): Promise { const executor = await this.cellExecutorForLanguage(context.activeLanguage, editor.document, this.engine_); if (executor) { let code: string[] | undefined; @@ -596,8 +596,8 @@ class RunAllCellsCommand extends RunCommand implements Command { override async doExecuteVisualMode( editor: QuartoVisualEditor, context: CodeViewActiveBlockContext - ) : Promise { - const code : string[] = []; + ): Promise { + const code: string[] = []; for (const block of context.blocks) { if (block.language === context.activeLanguage) { code.push(block.code); @@ -615,7 +615,7 @@ class RunAllCellsCommand extends RunCommand implements Command { class GoToCellCommand { constructor( - host: ExtensionHost, + host: ExtensionHost, engine: MarkdownEngine, dir: "next" | "previous" ) { @@ -651,7 +651,7 @@ class GoToCellCommand { } } } - + } @@ -695,17 +695,17 @@ function navigateToBlock(editor: TextEditor, block: Token) { } function nextBlock( - host: ExtensionHost, - line: number, - tokens: Token[], + host: ExtensionHost, + line: number, + tokens: Token[], requireEvaluated = false, requireExecutor = true -) : TokenMath | TokenCodeBlock | undefined { +): TokenMath | TokenCodeBlock | undefined { for (const block of tokens.filter( - requireExecutor - ? requireEvaluated - ? (token?: Token) => blockIsExecutable(host, token) - : (token?: Token) => blockHasExecutor(host, token) + requireExecutor + ? requireEvaluated + ? (token?: Token) => blockIsExecutable(host, token) + : (token?: Token) => blockHasExecutor(host, token) : (token?: Token) => token && isExecutableLanguageBlock(token) && !isDisplayMath(token) )) { if (block.range.start.line > line) { @@ -721,13 +721,13 @@ function previousBlock( tokens: Token[], requireEvaluated = false, requireExecutor = true -) : TokenMath | TokenCodeBlock | undefined { +): TokenMath | TokenCodeBlock | undefined { for (const block of tokens .filter( - requireExecutor - ? requireEvaluated - ? (token?: Token) => blockIsExecutable(host, token) - : (token?: Token) => blockHasExecutor(host, token) + requireExecutor + ? requireEvaluated + ? (token?: Token) => blockIsExecutable(host, token) + : (token?: Token) => blockHasExecutor(host, token) : (token?: Token) => token && isExecutableLanguageBlock(token) && !isDisplayMath(token)) .reverse()) { if (block.range.end.line < line) { diff --git a/apps/vscode/src/providers/cell/executors.ts b/apps/vscode/src/providers/cell/executors.ts index b3617c22..e6092386 100644 --- a/apps/vscode/src/providers/cell/executors.ts +++ b/apps/vscode/src/providers/cell/executors.ts @@ -19,13 +19,13 @@ import { TextDocument } from "vscode"; -import { - codeForExecutableLanguageBlock, - isExecutableLanguageBlock, - languageNameFromBlock, - Token, - TokenCodeBlock, - TokenMath +import { + codeForExecutableLanguageBlock, + isExecutableLanguageBlock, + languageNameFromBlock, + Token, + TokenCodeBlock, + TokenMath } from "quarto-core"; import { lines } from "core"; @@ -40,7 +40,7 @@ export function hasExecutor(_host: ExtensionHost, language: string) { return executableLanguages().includes(language); } -export function blockHasExecutor(host: ExtensionHost, token?: Token) : token is TokenMath | TokenCodeBlock { +export function blockHasExecutor(host: ExtensionHost, token?: Token): token is TokenMath | TokenCodeBlock { if (token) { const language = languageNameFromBlock(token); return isExecutableLanguageBlock(token) && hasExecutor(host, language); @@ -49,7 +49,7 @@ export function blockHasExecutor(host: ExtensionHost, token?: Token) : token is } } -export function blockIsExecutable(host: ExtensionHost, token?: Token) : token is TokenMath | TokenCodeBlock { +export function blockIsExecutable(host: ExtensionHost, token?: Token): token is TokenMath | TokenCodeBlock { if (token) { return ( blockHasExecutor(host, token) && cellOptionsForToken(token)[kExecuteEval] !== false @@ -73,13 +73,13 @@ export function codeWithoutOptionsFromBlock(token: TokenMath | TokenCodeBlock) { } else { return ""; } - } else { - return codeForExecutableLanguageBlock(token); - } + } else { + return codeForExecutableLanguageBlock(token); + } } else { return ""; } - + } export async function executeInteractive( diff --git a/apps/vscode/src/providers/cell/options.ts b/apps/vscode/src/providers/cell/options.ts index 2a9bfd40..936c09c0 100644 --- a/apps/vscode/src/providers/cell/options.ts +++ b/apps/vscode/src/providers/cell/options.ts @@ -33,7 +33,7 @@ export function cellOptionsForToken(token: Token): Record { } export function cellOptions(language: string, source: string[]): Record { - + const commentChars = langCommentChars(language); const optionPattern = optionCommentPattern(commentChars[0]); const optionSuffix = commentChars[1] || ""; @@ -70,7 +70,7 @@ export function cellOptions(language: string, source: string[]): Record; + return options as Record; } else { return {}; } diff --git a/apps/vscode/src/providers/create/create-project.ts b/apps/vscode/src/providers/create/create-project.ts index f6f0be11..8312c710 100644 --- a/apps/vscode/src/providers/create/create-project.ts +++ b/apps/vscode/src/providers/create/create-project.ts @@ -27,7 +27,7 @@ export class CreateProjectCommand implements Command { public readonly id: string, private readonly context_: ExtensionContext, private readonly quartoContext_: QuartoContext - ) {} + ) { } async execute() { await withMinimumQuartoVersion( diff --git a/apps/vscode/src/providers/create/create.ts b/apps/vscode/src/providers/create/create.ts index ff03af71..1de82605 100644 --- a/apps/vscode/src/providers/create/create.ts +++ b/apps/vscode/src/providers/create/create.ts @@ -30,7 +30,7 @@ export async function activateCreate( await window.showTextDocument(doc, ViewColumn.Active, false); } } - + // commands return [ new CreateProjectCommand("quarto.createProject", context, quartoContext), diff --git a/apps/vscode/src/providers/deno-config.ts b/apps/vscode/src/providers/deno-config.ts index 1f6ab238..4188ff20 100644 --- a/apps/vscode/src/providers/deno-config.ts +++ b/apps/vscode/src/providers/deno-config.ts @@ -34,7 +34,7 @@ export function activateDenoConfig(context: ExtensionContext, engine: MarkdownEn if (isDenoDocument(doc, engine)) { await config.update("deno.enable", true, null); } - + } } }; diff --git a/apps/vscode/src/providers/diagram/codelens.ts b/apps/vscode/src/providers/diagram/codelens.ts index d85f551c..25d03bf2 100644 --- a/apps/vscode/src/providers/diagram/codelens.ts +++ b/apps/vscode/src/providers/diagram/codelens.ts @@ -42,7 +42,7 @@ export function diagramCodeLensProvider( } const block = diagramBlocks[i]; - + // push code lens const range = new Range(block.range.start.line, 0, block.range.start.line, 0); lenses.push( @@ -55,7 +55,7 @@ export function diagramCodeLensProvider( }), ] ); - + } return lenses; }, diff --git a/apps/vscode/src/providers/diagram/commands.ts b/apps/vscode/src/providers/diagram/commands.ts index 68e8e27c..5cf6db56 100644 --- a/apps/vscode/src/providers/diagram/commands.ts +++ b/apps/vscode/src/providers/diagram/commands.ts @@ -41,7 +41,7 @@ export function diagramCommands( class PreviewDiagramCommand implements Command { - constructor(private readonly manager_: QuartoDiagramWebviewManager) {} + constructor(private readonly manager_: QuartoDiagramWebviewManager) { } execute(options?: PreviewDiagramOptions): void { // set selection to line if requested if (options?.textEditorLine !== undefined && window.activeTextEditor) { @@ -58,7 +58,7 @@ class PreviewDiagramCommand implements Command { } class PreviewContentShortcutCommand implements Command { - constructor(private readonly engine_: MarkdownEngine) {} + constructor(private readonly engine_: MarkdownEngine) { } async execute(): Promise { // first determine whether this is an alias for preview math or preview diagram if (window.activeTextEditor) { @@ -91,11 +91,11 @@ class PreviewContentShortcutCommand implements Command { activate: true }); } else { - // info message + // info message window.showInformationMessage( "No content preview available (selection not within an equation or diagram)" ); - } + } } } diff --git a/apps/vscode/src/providers/diagram/diagram-webview.ts b/apps/vscode/src/providers/diagram/diagram-webview.ts index f1ac23b0..5430dca1 100644 --- a/apps/vscode/src/providers/diagram/diagram-webview.ts +++ b/apps/vscode/src/providers/diagram/diagram-webview.ts @@ -64,7 +64,7 @@ export class QuartoDiagramWebviewManager extends QuartoWebviewManager< } public showDiagram(state?: DiagramState, activate = true) { - + if (!this.activeView_ && !activate) { return; } @@ -89,14 +89,14 @@ export class QuartoDiagramWebviewManager extends QuartoWebviewManager< private async updatePreview(state?: DiagramState) { - + if (this.isVisible()) { // see if there is an explcit state update (otherwise inspect hte active editor) if (state) { - + this.updateViewState(state); - - // inspect the active editor for a diagram + + // inspect the active editor for a diagram } else if (window.activeTextEditor) { const doc = window.activeTextEditor.document; if (isQuartoDoc(doc) && window.activeTextEditor.selection) { @@ -127,7 +127,7 @@ export class QuartoDiagramWebviewManager extends QuartoWebviewManager< if (veDiagram) { this.updateViewState(veDiagram); } - } + } } } diff --git a/apps/vscode/src/providers/diagram/diagram.ts b/apps/vscode/src/providers/diagram/diagram.ts index 73ac3319..2bbc16fd 100644 --- a/apps/vscode/src/providers/diagram/diagram.ts +++ b/apps/vscode/src/providers/diagram/diagram.ts @@ -47,13 +47,13 @@ export function activateDiagram( return diagramCommands(diagramManager, engine); } -export async function visualEditorDiagramState() : Promise { - +export async function visualEditorDiagramState(): Promise { + const visualEditor = VisualEditorProvider.activeEditor(); if (visualEditor) { const blockContext = await visualEditor.getActiveBlockContext(); if (blockContext) { - const engine = languageDiagramEngine(blockContext.activeLanguage); + const engine = languageDiagramEngine(blockContext.activeLanguage); if (engine) { const activeBlock = blockContext.blocks.find(block => block.active); if (activeBlock) { diff --git a/apps/vscode/src/providers/editor/codeview.ts b/apps/vscode/src/providers/editor/codeview.ts index 839a7067..1d08938c 100644 --- a/apps/vscode/src/providers/editor/codeview.ts +++ b/apps/vscode/src/providers/editor/codeview.ts @@ -13,35 +13,35 @@ * */ -import { - CompletionItem as VCompletionItem, - CompletionItemKind as VCompletionItemKind, - MarkdownString, - SnippetString, +import { + CompletionItem as VCompletionItem, + CompletionItemKind as VCompletionItemKind, + MarkdownString, + SnippetString, Range, Position, - TextDocument, + TextDocument, commands } from "vscode"; -import { - CompletionItem, - CompletionItemKind, - CompletionItemLabelDetails, - CompletionList, - InsertTextFormat, - MarkupContent, - MarkupKind +import { + CompletionItem, + CompletionItemKind, + CompletionItemLabelDetails, + CompletionList, + InsertTextFormat, + MarkupContent, + MarkupKind } from "vscode-languageserver-types"; import { JsonRpcRequestTransport } from "core"; -import { +import { CodeViewCellContext, - CodeViewCompletionContext, - CodeViewExecute, - CodeViewServer, - DiagramState, + CodeViewCompletionContext, + CodeViewExecute, + CodeViewServer, + DiagramState, kCodeViewGetCompletions, } from "editor-types"; @@ -51,13 +51,13 @@ import { vdocCompletions } from "../../vdoc/vdoc-completion"; import { MarkdownEngine } from "../../markdown/engine"; -export function vscodeCodeViewServer(_engine: MarkdownEngine, document: TextDocument, lspRequest: JsonRpcRequestTransport) : CodeViewServer { +export function vscodeCodeViewServer(_engine: MarkdownEngine, document: TextDocument, lspRequest: JsonRpcRequestTransport): CodeViewServer { return { async codeViewAssist(context: CodeViewCellContext) { await commands.executeCommand("quarto.codeViewAssist", context, lspRequest); }, async codeViewExecute(execute: CodeViewExecute) { - switch(execute) { + switch (execute) { case "cell": await commands.executeCommand("quarto.runCurrentCell"); break; @@ -72,31 +72,31 @@ export function vscodeCodeViewServer(_engine: MarkdownEngine, document: TextDocu break; } }, - async codeViewCompletions(context: CodeViewCompletionContext) : Promise { + async codeViewCompletions(context: CodeViewCompletionContext): Promise { // if this is yaml then call the lsp directly if (context.language === "yaml") { return lspRequest(kCodeViewGetCompletions, [context]); - + } else { - + // see if we have an embedded langaage const language = embeddedLanguage(context.language); if (language) { - + // if this is a yaml comment line then call the lsp const line = context.code[context.selection.start.line]; if (language.comment && line.startsWith(`${language.comment}| `)) { return lspCellYamlOptionsCompletions(context, lspRequest); - // otherwise delegate to vscode completion system + // otherwise delegate to vscode completion system } else { const vdoc = virtualDocForCode(context.code, language); const completions = await vdocCompletions( vdoc, new Position( - context.selection.start.line, + context.selection.start.line, context.selection.start.character ), undefined, @@ -113,7 +113,7 @@ export function vscodeCodeViewServer(_engine: MarkdownEngine, document: TextDocu items: [], isIncomplete: false }; - } + } } }, async codeViewPreviewDiagram(state: DiagramState, activate: boolean) { @@ -123,8 +123,8 @@ export function vscodeCodeViewServer(_engine: MarkdownEngine, document: TextDocu } function lspCellYamlOptionsCompletions(context: CodeViewCompletionContext, lspRequest: JsonRpcRequestTransport) { - // strip out lines that aren't in the code block - const code = context.code.map((codeLine, index) => { + // strip out lines that aren't in the code block + const code = context.code.map((codeLine, index) => { if (index < context.cellBegin || index > context.cellEnd) { return ""; } else { @@ -151,32 +151,32 @@ function lspCellYamlOptionsCompletions(context: CodeViewCompletionContext, lspRe }]); } -export function vsCompletionItemToLsCompletionItem(item: VCompletionItem) : CompletionItem { - const insertText = item.insertText instanceof SnippetString +export function vsCompletionItemToLsCompletionItem(item: VCompletionItem): CompletionItem { + const insertText = item.insertText instanceof SnippetString ? item.insertText.value : item.insertText || ""; const completion: CompletionItem = { ...labelWithDetails(item), kind: vsKindToLsKind(item.kind), detail: item.detail, - documentation: item.documentation instanceof MarkdownString - ? mdStringToMdContent(item.documentation) + documentation: item.documentation instanceof MarkdownString + ? mdStringToMdContent(item.documentation) : item.documentation, sortText: item.sortText && /^\d/.test(item.sortText) ? item.sortText : undefined, filterText: item.filterText, insertText, - insertTextFormat: item.insertText instanceof SnippetString - ? InsertTextFormat.Snippet + insertTextFormat: item.insertText instanceof SnippetString + ? InsertTextFormat.Snippet : InsertTextFormat.PlainText, command: item.command }; if (item.range) { - const isRange = (x?: unknown) : x is Range => { return !!x && !!(x as Record).start; }; + const isRange = (x?: unknown): x is Range => { return !!x && !!(x as Record).start; }; if (isRange(item.range)) { completion.textEdit = { newText: insertText, range: { - start: item.range.start, + start: item.range.start, end: item.range.end } }; @@ -184,7 +184,7 @@ export function vsCompletionItemToLsCompletionItem(item: VCompletionItem) : Comp completion.textEdit = { newText: insertText, insert: { - start: item.range.inserting.start, + start: item.range.inserting.start, end: item.range.replacing.end }, replace: { @@ -192,15 +192,15 @@ export function vsCompletionItemToLsCompletionItem(item: VCompletionItem) : Comp end: item.range.replacing.end } }; - + } } return completion; - + } -export function labelWithDetails(item: VCompletionItem) : { label: string, labelWithDetails: CompletionItemLabelDetails} { - if (typeof(item.label) === "string") { +export function labelWithDetails(item: VCompletionItem): { label: string, labelWithDetails: CompletionItemLabelDetails } { + if (typeof (item.label) === "string") { return { label: item.label, labelWithDetails: { @@ -217,12 +217,12 @@ export function labelWithDetails(item: VCompletionItem) : { label: string, label } } -export function vsKindToLsKind(kind?: VCompletionItemKind) : CompletionItemKind | undefined{ +export function vsKindToLsKind(kind?: VCompletionItemKind): CompletionItemKind | undefined { if (kind === undefined) { return undefined; } - switch(kind) { + switch (kind) { case VCompletionItemKind.Text: return CompletionItemKind.Text; case VCompletionItemKind.Method: @@ -280,7 +280,7 @@ export function vsKindToLsKind(kind?: VCompletionItemKind) : CompletionItemKind } } -function mdStringToMdContent(mdString: MarkdownString) : MarkupContent { +function mdStringToMdContent(mdString: MarkdownString): MarkupContent { return { kind: MarkupKind.Markdown, value: mdString.value diff --git a/apps/vscode/src/providers/editor/connection.ts b/apps/vscode/src/providers/editor/connection.ts index 1bb1744e..e5783280 100644 --- a/apps/vscode/src/providers/editor/connection.ts +++ b/apps/vscode/src/providers/editor/connection.ts @@ -17,21 +17,21 @@ import { Disposable, WebviewPanel } from "vscode"; -import { +import { VSC_VE_Init, VSC_VE_Focus, VSC_VE_GetMarkdownFromState, VSC_VE_GetSlideIndex, - VSC_VE_ApplyExternalEdit, + VSC_VE_ApplyExternalEdit, VSC_VE_GetActiveBlockContext, VSC_VE_SetBlockSelection, VSC_VEH_EditorResourceUri, - VSC_VEH_GetHostContext, + VSC_VEH_GetHostContext, VSC_VEH_ReopenSourceMode, VSC_VEH_OnEditorUpdated, VSC_VEH_OnEditorStateChanged, VSC_VEH_FlushEditorUpdates, - VSC_VEH_OnEditorReady, + VSC_VEH_OnEditorReady, VSC_VEH_OpenURL, VSC_VEH_NavigateToXRef, VSC_VEH_NavigateToFile, @@ -53,23 +53,23 @@ import { CodeViewSelectionAction } from "editor-types"; -import { - jsonRpcPostMessageServer, - JsonRpcPostMessageTarget, +import { + jsonRpcPostMessageServer, + JsonRpcPostMessageTarget, JsonRpcServerMethod, jsonRpcPostMessageRequestTransport, JsonRpcRequestTransport } from "core"; -import { +import { prefsServerMethods, codeViewServerMethods } from "editor-server"; import { zoteroLspProxy } from "../zotero/zotero"; // interface to visual editor (vscode custom editor embedded in iframe) -export function visualEditorClient(webviewPanel: WebviewPanel) +export function visualEditorClient(webviewPanel: WebviewPanel) : { editor: VSCodeVisualEditor, connected: () => boolean, dispose: VoidFunction } { let isConnected = true; @@ -85,7 +85,7 @@ export function visualEditorClient(webviewPanel: WebviewPanel) getSlideIndex: () => request(VSC_VE_GetSlideIndex, []), getActiveBlockContext: () => request(VSC_VE_GetActiveBlockContext, []), setBlockSelection: ( - context: CodeViewActiveBlockContext, + context: CodeViewActiveBlockContext, action: CodeViewSelectionAction ) => request(VSC_VE_SetBlockSelection, [context, action]), applyExternalEdit: (markdown: string) => request(VSC_VE_ApplyExternalEdit, [markdown]), @@ -108,9 +108,9 @@ export function visualEditorServer( host: VSCodeVisualEditorHost, prefsServer: PrefsServer, codeViewServer: CodeViewServer -) : Disposable { - - +): Disposable { + + // table of methods we implement directly const extensionMethods = { ...prefsServerMethods(prefsServer), @@ -138,7 +138,7 @@ export function visualEditorServer( -function editorHostMethods(host: VSCodeVisualEditorHost) : Record { +function editorHostMethods(host: VSCodeVisualEditorHost): Record { const methods: Record = { [VSC_VEH_GetHostContext]: () => host.getHostContext(), [VSC_VEH_ReopenSourceMode]: () => host.reopenSourceMode(), @@ -162,7 +162,7 @@ function editorHostMethods(host: VSCodeVisualEditorHost) : Record Promise.resolve(); -function webviewPanelPostMessageTarget(webviewPanel: WebviewPanel) : JsonRpcPostMessageTarget { +function webviewPanelPostMessageTarget(webviewPanel: WebviewPanel): JsonRpcPostMessageTarget { return { postMessage: (data) => { webviewPanel.webview.postMessage(data); diff --git a/apps/vscode/src/providers/editor/editor.ts b/apps/vscode/src/providers/editor/editor.ts index f80cf909..52afddfa 100644 --- a/apps/vscode/src/providers/editor/editor.ts +++ b/apps/vscode/src/providers/editor/editor.ts @@ -17,16 +17,16 @@ import path, { extname } from "path"; import debounce from "lodash.debounce"; -import { +import { window, - workspace, - ExtensionContext, - Disposable, - CustomTextEditorProvider, - TextDocument, - WebviewPanel, - CancellationToken, - Uri, + workspace, + ExtensionContext, + Disposable, + CustomTextEditorProvider, + TextDocument, + WebviewPanel, + CancellationToken, + Uri, Webview, Range, env, @@ -58,18 +58,18 @@ import { MarkdownEngine } from "../../markdown/engine"; import { lspClientTransport } from "core-node"; import { editorSourceJsonRpcServer } from "editor-core"; import { JsonRpcRequestTransport } from "core"; -import { - editInSourceModeCommand, - editInVisualModeCommand, - reopenEditorInSourceMode +import { + editInSourceModeCommand, + editInVisualModeCommand, + reopenEditorInSourceMode } from "./toggle"; import { ExtensionHost } from "../../host"; export interface QuartoVisualEditor extends QuartoEditor { - hasFocus() : Promise; - getActiveBlockContext() : Promise; - setBlockSelection(context: CodeViewActiveBlockContext, action: CodeViewSelectionAction) : Promise; + hasFocus(): Promise; + getActiveBlockContext(): Promise; + setBlockSelection(context: CodeViewActiveBlockContext, action: CodeViewSelectionAction): Promise; } export function activateEditor( @@ -78,7 +78,7 @@ export function activateEditor( quartoContext: QuartoContext, lspClient: LanguageClient, engine: MarkdownEngine -) : Command[] { +): Command[] { // register the provider context.subscriptions.push(VisualEditorProvider.register(context, host, quartoContext, lspClient, engine)); @@ -88,33 +88,33 @@ export function activateEditor( export class VisualEditorProvider implements CustomTextEditorProvider { - + // track the last contents of any active untitled docs (used // for recovering from attempt to edit ) private static activeUntitled?: { uri: Uri, content: string }; // track the last edited line of code in text editors (used for syncing position) - private static editorLastSourcePos = new Map(); + private static editorLastSourcePos = new Map(); // track the list source location in visual editors (used for syncing position) - private static visualEditorLastSourcePos = new Map(); + private static visualEditorLastSourcePos = new Map(); // track pending switch to source private static visualEditorPendingSwitchToSource = new Set(); // track pending xref navigations - private static visualEditorPendingXRefNavigations = new Map(); + private static visualEditorPendingXRefNavigations = new Map(); // track visual editors private static visualEditors = visualEditorTracker(); public static register( - context: ExtensionContext, + context: ExtensionContext, host: ExtensionHost, quartoContext: QuartoContext, lspClient: LanguageClient, engine: MarkdownEngine - ) : Disposable { + ): Disposable { // setup request transport const lspRequest = lspClientTransport(lspClient); @@ -149,7 +149,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider { const document = editor.document; if (document && isQuartoDoc(document)) { const uri = document.uri.toString(); - + // check for switch (one shot) const isSwitch = this.visualEditorPendingSwitchToSource.has(uri); this.visualEditorPendingSwitchToSource.delete(uri); @@ -166,7 +166,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider { // find the index let cursorIndex = -1; - for (let i=(pos.locations.length-1); i>=0; i--) { + for (let i = (pos.locations.length - 1); i >= 0; i--) { if (pos.pos >= pos.locations[i].pos) { cursorIndex = i; break; @@ -178,11 +178,11 @@ export class VisualEditorProvider implements CustomTextEditorProvider { source.getSourcePosLocations(document.getText()).then(locations => { // map to source line const selLine = (cursorIndex !== -1 && (locations.length > cursorIndex)) - ? (locations[cursorIndex] || locations[locations.length-1]).pos - 1 + ? (locations[cursorIndex] || locations[locations.length - 1]).pos - 1 : 0; // navigate - const selRange = new Range(selLine, 0, selLine, 0); + const selRange = new Range(selLine, 0, selLine, 0); editor.selection = new Selection(selRange.start, selRange.end); editor.revealRange(selRange, TextEditorRevealType.InCenter); }); @@ -209,11 +209,11 @@ export class VisualEditorProvider implements CustomTextEditorProvider { this.visualEditorPendingSwitchToSource.add(document.uri.toString()); } - public static activeEditor(includeVisible?: boolean) : QuartoVisualEditor | undefined { + public static activeEditor(includeVisible?: boolean): QuartoVisualEditor | undefined { const editor = this.visualEditors.activeEditor(includeVisible); if (editor) { - return { - document: editor.document, + return { + document: editor.document, hasFocus: async () => { return await editor.editor.isFocused(); }, @@ -229,14 +229,14 @@ export class VisualEditorProvider implements CustomTextEditorProvider { setBlockSelection: async (context, action) => { await editor.editor.setBlockSelection(context, action); }, - viewColumn: editor.webviewPanel.viewColumn + viewColumn: editor.webviewPanel.viewColumn }; } else { return undefined; } } - public static editorForUri(uri: Uri) : TrackedEditor | undefined { + public static editorForUri(uri: Uri): TrackedEditor | undefined { return this.visualEditors.editorForUri(uri); } @@ -245,23 +245,23 @@ export class VisualEditorProvider implements CustomTextEditorProvider { } constructor(private readonly context: ExtensionContext, - private readonly extensionHost: ExtensionHost, - private readonly quartoContext: QuartoContext, - private readonly lspRequest: JsonRpcRequestTransport, - private readonly engine: MarkdownEngine) {} + private readonly extensionHost: ExtensionHost, + private readonly quartoContext: QuartoContext, + private readonly lspRequest: JsonRpcRequestTransport, + private readonly engine: MarkdownEngine) { } + - public async resolveCustomTextEditor( document: TextDocument, webviewPanel: WebviewPanel, _token: CancellationToken ) { - // if the document is untitled then capture its contents (as vscode throws it on the floor + // if the document is untitled then capture its contents (as vscode throws it on the floor // and we may need it to do a re-open) - const untitledContent = - (document.isUntitled && - VisualEditorProvider.activeUntitled?.uri.toString() === document.uri.toString()) + const untitledContent = + (document.isUntitled && + VisualEditorProvider.activeUntitled?.uri.toString() === document.uri.toString()) ? VisualEditorProvider.activeUntitled.content : undefined; @@ -277,11 +277,11 @@ export class VisualEditorProvider implements CustomTextEditorProvider { const kLearnMore = "Learn More..."; const result = await window.showInformationMessage( "You are activating Quarto visual markdown editing mode.", - { - modal: true, - detail: - "Visual mode enables you to author using a familiar word processor style interface.\n\n" + - "Markdown code will be re-formatted using the Pandoc markdown writer." + { + modal: true, + detail: + "Visual mode enables you to author using a familiar word processor style interface.\n\n" + + "Markdown code will be re-formatted using the Pandoc markdown writer." }, kUseVisualMode, kLearnMore @@ -297,7 +297,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider { this.context.globalState.update(kVisualModeConfirmed, true); } } - + // some storage locations const projectDir = document.isUntitled ? undefined : projectDirForDocument(document.fileName); const workspaceDir = this.quartoContext.workspaceDir; @@ -318,11 +318,11 @@ export class VisualEditorProvider implements CustomTextEditorProvider { const xref = VisualEditorProvider.visualEditorPendingXRefNavigations.get(sourceUri); VisualEditorProvider.visualEditorPendingXRefNavigations.delete(sourceUri); - // sync manager + // sync manager const syncManager = editorSyncManager( - document, - client.editor, - this.lspRequest, + document, + client.editor, + this.lspRequest, xref || sourcePos ); @@ -330,12 +330,12 @@ export class VisualEditorProvider implements CustomTextEditorProvider { const host: VSCodeVisualEditorHost = { // editor is querying for context - getHostContext: async () : Promise => { + getHostContext: async (): Promise => { return { documentPath: document.isUntitled ? null : document.fileName, projectDir, - resourceDir: document.isUntitled - ? (workspaceDir || process.cwd()) + resourceDir: document.isUntitled + ? (workspaceDir || process.cwd()) : path.dirname(document.fileName), isWindowsDesktop: isWindows(), executableLanguages: this.extensionHost.executableLanguages(true, document, this.engine) @@ -442,9 +442,9 @@ export class VisualEditorProvider implements CustomTextEditorProvider { // setup server on webview iframe disposables.push(visualEditorServer( - webviewPanel, - this.lspRequest, - host, + webviewPanel, + this.lspRequest, + host, prefsServer, vscodeCodeViewServer(this.engine, document, this.lspRequest) )); @@ -454,7 +454,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider { // monitor image file changes const kImagePattern = '**/*.{png,svg,jpg,jpeg}'; - const globPattern : GlobPattern = docDir + const globPattern: GlobPattern = docDir ? { baseUri: Uri.file(docDir), base: docDir, pattern: kImagePattern } : kImagePattern; const watcher = workspace.createFileSystemWatcher(globPattern); @@ -467,13 +467,13 @@ export class VisualEditorProvider implements CustomTextEditorProvider { watcher.onDidDelete(onChange); // load editor webview (include current doc path in localResourceRoots) - webviewPanel.webview.options = { + webviewPanel.webview.options = { localResourceRoots: [ - this.context.extensionUri, + this.context.extensionUri, ...(workspace.workspaceFolders ? workspace.workspaceFolders.map(folder => folder.uri) : []), ...(docDir ? [Uri.file(docDir)] : []) ], - enableScripts: true + enableScripts: true }; webviewPanel.webview.html = this.getHtmlForWebview(webviewPanel.webview); @@ -486,7 +486,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider { disposable.dispose(); } }); - + } private editorAssetUri(webview: Webview, file: string) { @@ -503,7 +503,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider { * Get the static html used for the editor webviews. */ private getHtmlForWebview(webview: Webview): string { - + const scriptUri = this.editorAssetUri(webview, "index.js"); const stylesUri = this.editorAssetUri(webview, "style.css"); const codiconsUri = this.extensionResourceUrl(webview, [ @@ -553,7 +553,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider { } async function navigateToFile(baseDoc: TextDocument, file: string, xref?: XRef) { - + const docDir = path.dirname(baseDoc.uri.fsPath); const filePath = path.normalize(path.isAbsolute(file) ? file : path.join(docDir, file)); const uri = Uri.file(filePath); @@ -575,11 +575,11 @@ async function navigateToFile(baseDoc: TextDocument, file: string, xref?: XRef) } else { await openWith(VisualEditorProvider.viewType); } - + } else if (ext === ".ipynb") { - + await openWith("jupyter-notebook"); - + } else { const doc = await workspace.openTextDocument(uri); @@ -608,13 +608,13 @@ interface VisualEditorTracker { activeEditor: (includeVisible?: boolean) => TrackedEditor | undefined; } -function visualEditorTracker() : VisualEditorTracker { +function visualEditorTracker(): VisualEditorTracker { const activeEditors = new Array(); return { - track: (document: TextDocument, webviewPanel: WebviewPanel, editor: VSCodeVisualEditor) : Disposable => { - activeEditors.push({document, webviewPanel, editor}); + track: (document: TextDocument, webviewPanel: WebviewPanel, editor: VSCodeVisualEditor): Disposable => { + activeEditors.push({ document, webviewPanel, editor }); return { dispose: () => { const idx = activeEditors.findIndex(editor => editor.webviewPanel === webviewPanel); @@ -631,20 +631,20 @@ function visualEditorTracker() : VisualEditorTracker { return activeEditors.find(editor => { try { return editor.webviewPanel.active || (includeVisible && editor.webviewPanel.visible); - } catch(err) { + } catch (err) { // we've seen activeEditors hold on to references to disposed editors (can't on the // surface see how this would occur as we subscribe to dispose, but as an insurance // policy let's eat any exception that occurs, since a single zombie webviewPanel // would prevent rendering of other panels return false; - } - + } + }); } }; } -function focusTracker(webviewPanel: WebviewPanel, editor: VSCodeVisualEditor) : Disposable { +function focusTracker(webviewPanel: WebviewPanel, editor: VSCodeVisualEditor): Disposable { let hasFocus = false; let cancelled = false; @@ -655,18 +655,18 @@ function focusTracker(webviewPanel: WebviewPanel, editor: VSCodeVisualEditor) : editor.focus(); }; - // if we are focused when the window loses focus then restore on re-focus - let reFocus = false; - const evWindow = window.onDidChangeWindowState(async (event) => { - if (!event.focused && hasFocus) { - reFocus = true; - } else if (event.focused && reFocus) { - setTimeout(async () => { + // if we are focused when the window loses focus then restore on re-focus + let reFocus = false; + const evWindow = window.onDidChangeWindowState(async (event) => { + if (!event.focused && hasFocus) { + reFocus = true; + } else if (event.focused && reFocus) { + setTimeout(async () => { await focusEditor(); reFocus = false; - }, 200); - } - }); + }, 200); + } + }); // periodically check for focus const timer = setInterval(async () => { diff --git a/apps/vscode/src/providers/editor/images.ts b/apps/vscode/src/providers/editor/images.ts index 0379b621..d92a2324 100644 --- a/apps/vscode/src/providers/editor/images.ts +++ b/apps/vscode/src/providers/editor/images.ts @@ -26,10 +26,10 @@ import { isHttpUrl, kImageExtensions } from "core"; export function documentImageResolver( - doc: TextDocument, + doc: TextDocument, projectDir?: string -) : EditorUIImageResolver { - +): EditorUIImageResolver { + // compute doc and project dirs const docDir = path.normalize(path.dirname(doc.fileName)); projectDir = projectDir ? path.normalize(projectDir) : undefined; @@ -54,7 +54,7 @@ export function documentImageResolver( // try for a short name w/ integer, fallback to a longer one ext = ext || ".png"; const imagesDir = ensureImagesDir(); - for (let i=0; i<100; i++) { + for (let i = 0; i < 100; i++) { const imagePath = path.join(imagesDir, `${stem}${(i > 0 || !preserveStem) ? ('-' + (i + 1)) : ''}${ext}`); if (!fs.existsSync(imagePath)) { return imagePath; @@ -71,10 +71,10 @@ export function documentImageResolver( // doc dir relative if (uri.startsWith(docDir)) { return relative(docDir, uri); - // project dir relative (start w/ slash) + // project dir relative (start w/ slash) } else if (projectDir && uri.startsWith(projectDir)) { return `/${relative(projectDir, uri)}`; - // otherwise copy to images dir + // otherwise copy to images dir } else { const parsedPath = path.parse(uri); const imagePath = uniqueImagePath(parsedPath.name, parsedPath.ext, true); @@ -85,7 +85,7 @@ export function documentImageResolver( return { - resolveImageUris: async (uris: string[]) : Promise => { + resolveImageUris: async (uris: string[]): Promise => { return uris.map(uri => { if (isHttpUrl(uri)) { return uri; @@ -94,7 +94,7 @@ export function documentImageResolver( } }); }, - resolveBase64Images: async (base64Images: string[]) : Promise => { + resolveBase64Images: async (base64Images: string[]): Promise => { return base64Images.map(base64 => { const kImgRegex = /^data:image\/(\w+);base64,/; const match = base64.match(kImgRegex); @@ -107,10 +107,10 @@ export function documentImageResolver( } else { return null; } - ; + ; }).filter(image => image !== null) as string[]; }, - selectImage: async () : Promise => { + selectImage: async (): Promise => { const file = await vscode.window.showOpenDialog({ canSelectFiles: true, canSelectFolders: false, diff --git a/apps/vscode/src/providers/editor/prefs.ts b/apps/vscode/src/providers/editor/prefs.ts index 70a92010..16cb6522 100644 --- a/apps/vscode/src/providers/editor/prefs.ts +++ b/apps/vscode/src/providers/editor/prefs.ts @@ -79,25 +79,25 @@ export async function vscodePrefsServer( engine: MarkdownEngine, document: TextDocument, onPrefsChanged: (prefs: Prefs) => void -) : Promise<[PrefsServer, Disposable]> { +): Promise<[PrefsServer, Disposable]> { const server = prefsServer(); const defaults = defaultPrefs(); - const getPrefs = async () : Promise => { - + const getPrefs = async (): Promise => { + const configuration = workspace.getConfiguration(undefined, document.uri); - + const globalPrefs = await server.getPrefs(); - const prefs = { - + const prefs = { + ...(globalPrefs), - ...readPerDocumentPrefs(document, globalPrefs), + ...readPerDocumentPrefs(document, globalPrefs), // theme - darkMode: window.activeColorTheme.kind === ColorThemeKind.Dark || - window.activeColorTheme.kind === ColorThemeKind.HighContrast, + darkMode: window.activeColorTheme.kind === ColorThemeKind.Dark || + window.activeColorTheme.kind === ColorThemeKind.HighContrast, fontSize: configuration.get(kQuartoEditorFontSize, 0) || configuration.get(kEditorFontSize, defaults.fontSize), fontFamily: configuration.get(kQuartoEditorFontFamily) || configuration.get(kMarkdownPreviewFontFamily, defaults.fontFamily), maxContentWidth: configuration.get(kQuartoEditorMaxContentWidth, defaults.maxContentWidth), @@ -111,7 +111,7 @@ export async function vscodePrefsServer( // markdown writer settings ...(await readMarkdownPrefs(context, engine, document)), - + // vscode code editor settings spacesForTab: configuration.get(kEditorInsertSpaces, true), tabWidth: configuration.get(kEditorTabSize, 4), @@ -132,7 +132,7 @@ export async function vscodePrefsServer( const kThrottleDelayMs = 100; const firePrefsChanged = throttle(() => { getPrefs().then(onPrefsChanged); - }, kThrottleDelayMs, { leading: false, trailing: true}); + }, kThrottleDelayMs, { leading: false, trailing: true }); // subscribe to changes that can affect prefs @@ -172,11 +172,11 @@ export async function vscodePrefsServer( return [ { getPrefs, - setPrefs: async (prefs: Prefs) : Promise => { + setPrefs: async (prefs: Prefs): Promise => { server.setPrefs(prefs); writePerDocumentPrefs(document, prefs); } - }, + }, { dispose() { for (const disposable of disposables) { @@ -189,8 +189,8 @@ export async function vscodePrefsServer( async function readMarkdownPrefs( - context: QuartoContext, - engine: MarkdownEngine, + context: QuartoContext, + engine: MarkdownEngine, document: TextDocument ) { @@ -242,19 +242,19 @@ async function readMarkdownPrefs( return prefs; } -function resolveMarkdownPrefs(frontMatter: Record, prefs: MarkdownPrefs) { +function resolveMarkdownPrefs(frontMatter: Record, prefs: MarkdownPrefs) { // copy baseline prefs const resolved = { ...prefs }; // determine editor key - const editorKey = (frontMatter["editor"] || frontMatter["editor_options"]) as Record; + const editorKey = (frontMatter["editor"] || frontMatter["editor_options"]) as Record; if (!editorKey || typeof editorKey !== "object") { return resolved; } // markdown options - const markdownKey = editorKey["markdown"] as Record; + const markdownKey = editorKey["markdown"] as Record; if (!markdownKey || typeof markdownKey !== "object") { return resolved; } @@ -262,7 +262,7 @@ function resolveMarkdownPrefs(frontMatter: Record, prefs: Markdo // markdown wrap const wrap = markdownKey["wrap"]; if (wrap) { - if (typeof(wrap) === "number") { + if (typeof (wrap) === "number") { resolved.markdownWrap = "column"; resolved.markdownWrapColumn = wrap; } else if (wrap === "none") { @@ -273,8 +273,8 @@ function resolveMarkdownPrefs(frontMatter: Record, prefs: Markdo } // markdown references - const referencesKey = markdownKey["references"] as Record; - if (referencesKey && typeof(referencesKey) === "object") { + const referencesKey = markdownKey["references"] as Record; + if (referencesKey && typeof (referencesKey) === "object") { const location = referencesKey["location"]; if (location) { if (location === 'block') { @@ -286,7 +286,7 @@ function resolveMarkdownPrefs(frontMatter: Record, prefs: Markdo } } const prefix = referencesKey["prefix"]; - resolved.markdownReferencesPrefix = prefix && typeof(prefix) === "string" + resolved.markdownReferencesPrefix = prefix && typeof (prefix) === "string" ? prefix : resolved.markdownReferencesPrefix; @@ -302,7 +302,7 @@ interface PerDocumentPrefs { showOutline: boolean; } -function readPerDocumentPrefs(document: TextDocument, defaultPrefs: Prefs) : PerDocumentPrefs { +function readPerDocumentPrefs(document: TextDocument, defaultPrefs: Prefs): PerDocumentPrefs { const storage = filePrefsStorage(document.uri.fsPath); if (existsSync(storage)) { const prefs = JSON.parse(readFileSync(storage, { encoding: "utf8" })); diff --git a/apps/vscode/src/providers/editor/sync.ts b/apps/vscode/src/providers/editor/sync.ts index 4f4d9121..d2fbbb1c 100644 --- a/apps/vscode/src/providers/editor/sync.ts +++ b/apps/vscode/src/providers/editor/sync.ts @@ -49,7 +49,7 @@ For the visual editor propagating its own changes: */ export interface EditorSyncManager { - init: () => Promise; + init: () => Promise; onVisualEditorChanged: (state: unknown) => Promise; flushPendingUpdates: () => Promise; onDocumentChanged: () => Promise; @@ -59,11 +59,11 @@ export interface EditorSyncManager { // sync the document model w/ the visual editor export function editorSyncManager( - document: TextDocument, + document: TextDocument, visualEditor: VSCodeVisualEditor, request: JsonRpcRequestTransport, navigation?: XRef | number -) : EditorSyncManager { +): EditorSyncManager { // state: an update from the visual editor that we have yet to apply. we don't // apply these on every keystoke b/c they are expensive. we poll to apply these @@ -73,11 +73,11 @@ export function editorSyncManager( // state: don't propagate the next model change we get to the visual editor // (as the change actually resulted from a visual editor sync) - let supressNextUpdate = false; + let supressNextUpdate = false; // collect a pending edit, converting it to markdown and setting the supressNextUpdate bit // if we fail get the markdown then we neither clear the pending edit nor supress the update - const collectPendingVisualEdit = async () : Promise => { + const collectPendingVisualEdit = async (): Promise => { if (pendingVisualEdit) { const state = pendingVisualEdit; try { @@ -115,12 +115,12 @@ export function editorSyncManager( // initialize the connection to the visual editor by providing it // with its initial contents and syncing the canonnical markdown // back to the document - init: async() => { + init: async () => { // determine the current sourcePos const markdown = document.getText(); let initialNav: NavLocation | undefined; if (markdown) { - if (typeof(navigation) === "number") { + if (typeof (navigation) === "number") { const source = editorSourceJsonRpcServer(request); const locations = await source.getSourcePosLocations(markdown); initialNav = { locations, pos: navigation }; @@ -128,7 +128,7 @@ export function editorSyncManager( initialNav = navigation; } } - + const editorMarkdown = await visualEditor.init(markdown, initialNav); if (editorMarkdown && (editorMarkdown !== document.getText())) { await updateWorkspaceDocument(document, editorMarkdown); @@ -156,7 +156,7 @@ export function editorSyncManager( }, // notification that we are saving (allow flusing of visual editor changes) - onDocumentSaving: async () : Promise => { + onDocumentSaving: async (): Promise => { // attempt to collect pending edit const markdown = await collectPendingVisualEdit(); if (markdown) { @@ -172,7 +172,7 @@ export function editorSyncManager( // notification that a document completed saving (failsafe for changes // that didn't get applied b/c of onDocumentSaving no longer being // called b/c vscode deems that it is running for too long) - onDocumentSaved: async () : Promise => { + onDocumentSaved: async (): Promise => { collectAndApplyPendingVisualEdit(); } }; diff --git a/apps/vscode/src/providers/editor/toggle.ts b/apps/vscode/src/providers/editor/toggle.ts index e0344be9..95bb0545 100644 --- a/apps/vscode/src/providers/editor/toggle.ts +++ b/apps/vscode/src/providers/editor/toggle.ts @@ -21,7 +21,7 @@ import { VisualEditorProvider } from "./editor"; -export function editInVisualModeCommand() : Command { +export function editInVisualModeCommand(): Command { return { id: "quarto.editInVisualMode", execute() { @@ -33,14 +33,14 @@ export function editInVisualModeCommand() : Command { }; } -export function editInSourceModeCommand() : Command { +export function editInSourceModeCommand(): Command { return { id: "quarto.editInSourceMode", execute() { const activeVisual = VisualEditorProvider.activeEditor(); if (activeVisual) { reopenEditorInSourceMode(activeVisual.document, '', activeVisual.viewColumn); - } + } } }; } @@ -49,14 +49,14 @@ export async function reopenEditorInVisualMode( document: TextDocument, viewColumn?: ViewColumn ) { - + // save then close await commands.executeCommand("workbench.action.files.save"); await commands.executeCommand('workbench.action.closeActiveEditor'); // open in visual mode - await commands.executeCommand("vscode.openWith", - document.uri, + await commands.executeCommand("vscode.openWith", + document.uri, VisualEditorProvider.viewType, { viewColumn @@ -65,8 +65,8 @@ export async function reopenEditorInVisualMode( } export async function reopenEditorInSourceMode( - document: TextDocument, - untitledContent?: string, + document: TextDocument, + untitledContent?: string, viewColumn?: ViewColumn ) { if (!document.isUntitled) { @@ -91,5 +91,5 @@ export async function reopenEditorInSourceMode( await window.showTextDocument(doc, viewColumn, false); } }); - + } diff --git a/apps/vscode/src/providers/format.ts b/apps/vscode/src/providers/format.ts index 68b09f22..d36b07be 100644 --- a/apps/vscode/src/providers/format.ts +++ b/apps/vscode/src/providers/format.ts @@ -86,7 +86,7 @@ export function embeddedDocumentFormattingProvider(engine: MarkdownEngine) { ); } } else { - return (await formatActiveCell(editor, engine) ) || []; + return (await formatActiveCell(editor, engine)) || []; } } } @@ -130,7 +130,7 @@ export function embeddedDocumentRangeFormattingProvider( class FormatCellCommand implements Command { public readonly id = "quarto.formatCell"; - constructor(private readonly engine_: MarkdownEngine) {} + constructor(private readonly engine_: MarkdownEngine) { } public async execute(): Promise { const editor = window.activeTextEditor; diff --git a/apps/vscode/src/providers/insert.ts b/apps/vscode/src/providers/insert.ts index 22041593..564dbae3 100644 --- a/apps/vscode/src/providers/insert.ts +++ b/apps/vscode/src/providers/insert.ts @@ -30,7 +30,7 @@ export function insertCommands(engine: MarkdownEngine): Command[] { } class InsertCodeCellCommand implements Command { - constructor(private readonly engine_: MarkdownEngine) {} + constructor(private readonly engine_: MarkdownEngine) { } private static readonly id = "quarto.insertCodeCell"; public readonly id = InsertCodeCellCommand.id; diff --git a/apps/vscode/src/providers/lua-types.ts b/apps/vscode/src/providers/lua-types.ts index 0458fb0c..a52b899a 100644 --- a/apps/vscode/src/providers/lua-types.ts +++ b/apps/vscode/src/providers/lua-types.ts @@ -102,8 +102,8 @@ async function syncLuaTypes( const neverInstall: MessageItem = { title: "Don't Ask Again" }; const result = await window.showInformationMessage( "Quarto can provide completion and diagnostics for Lua scripts in this workspace if the " + - "[Lua extension](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) " + - "is installed. Do you want to install it now?", + "[Lua extension](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) " + + "is installed. Do you want to install it now?", install, notNow, neverInstall diff --git a/apps/vscode/src/providers/option.ts b/apps/vscode/src/providers/option.ts index c8925562..f49ee145 100644 --- a/apps/vscode/src/providers/option.ts +++ b/apps/vscode/src/providers/option.ts @@ -76,7 +76,7 @@ function handleOptionEnter(editor: TextEditor, comment: string) { // current line info const currentLineNumber = editor.selection.active.line; const currentLine = editor.document.lineAt(editor.selection.start).text; - + // apply edits if (currentLine.trim() === optionComment.trim()) { editor.edit((builder) => { diff --git a/apps/vscode/src/providers/preview/commands.ts b/apps/vscode/src/providers/preview/commands.ts index 876a9bb7..5117263b 100644 --- a/apps/vscode/src/providers/preview/commands.ts +++ b/apps/vscode/src/providers/preview/commands.ts @@ -63,11 +63,11 @@ abstract class PreviewDocumentCommandBase extends RenderCommand { !(await isPreviewRunningForDoc(targetEditor.document)); if (render) { if (format === kChooseFormat) { - - const frontMatter = targetEditor.notebook + + const frontMatter = targetEditor.notebook ? targetEditor.notebook.cellAt(0)?.document.getText() || "" : documentFrontMatterYaml(this.engine_, targetEditor.document); - + const formats = quartoDocumentFormats(this.quartoContext(), targetEditor.document.uri.fsPath, frontMatter); if (formats) { const declaredFormats = formats.filter(format => !!format.declared); @@ -81,7 +81,7 @@ abstract class PreviewDocumentCommandBase extends RenderCommand { const quickPick = window.createQuickPick(); quickPick.canSelectMany = false; const items: FormatQuickPickItem[] = []; - + // declared formats items.push({ format: "default", @@ -126,8 +126,7 @@ abstract class PreviewDocumentCommandBase extends RenderCommand { class PreviewCommand extends PreviewDocumentCommandBase - implements Command -{ + implements Command { constructor(quartoContext: QuartoContext, engine: MarkdownEngine) { super(quartoContext, engine); } @@ -141,8 +140,7 @@ class PreviewCommand class PreviewScriptCommand extends PreviewDocumentCommandBase - implements Command -{ + implements Command { constructor(quartoContext: QuartoContext, engine: MarkdownEngine) { super(quartoContext, engine); } @@ -156,8 +154,7 @@ class PreviewScriptCommand class PreviewFormatCommand extends PreviewDocumentCommandBase - implements Command -{ + implements Command { constructor(quartoContext: QuartoContext, engine: MarkdownEngine) { super(quartoContext, engine); } @@ -187,7 +184,7 @@ class ClearCacheCommand implements Command { constructor( private readonly quartoContext_: QuartoContext, private readonly engine_: MarkdownEngine - ) {} + ) { } async execute(): Promise { // see if there is a cache to clear diff --git a/apps/vscode/src/providers/preview/preview-env.ts b/apps/vscode/src/providers/preview/preview-env.ts index 1ff5bedf..d56820c3 100644 --- a/apps/vscode/src/providers/preview/preview-env.ts +++ b/apps/vscode/src/providers/preview/preview-env.ts @@ -45,19 +45,19 @@ export class PreviewEnvManager { } public async previewEnv(uri: Uri) { - + const env: PreviewEnv = { // eslint-disable-next-line @typescript-eslint/naming-convention - QUARTO_LOG: this.outputFile_, - + QUARTO_LOG: this.outputFile_, + // eslint-disable-next-line @typescript-eslint/naming-convention QUARTO_RENDER_TOKEN: this.renderToken_, ...(await terminalEnv(uri)) - + }; - + return env; } private readonly outputFile_: string; diff --git a/apps/vscode/src/providers/preview/preview-util.ts b/apps/vscode/src/providers/preview/preview-util.ts index 1f0fddd0..491919cc 100644 --- a/apps/vscode/src/providers/preview/preview-util.ts +++ b/apps/vscode/src/providers/preview/preview-util.ts @@ -56,7 +56,7 @@ export function isQuartoShinyKnitrDoc( doc?: TextDocument ) { return doc && isQuartoShinyDoc(engine, doc) && isKnitrDocument(doc, engine); - + } export async function isRPackage(): Promise { @@ -126,7 +126,7 @@ export async function renderOnSave(engine: MarkdownEngine, document: TextDocumen // finally, consult vs code settings const config = workspace.getConfiguration("quarto"); const render = isQuartoShinyDoc(engine, document) - ? config.get("render.renderOnSaveShiny", true) + ? config.get("render.renderOnSaveShiny", true) : config.get("render.renderOnSave", false); return render; diff --git a/apps/vscode/src/providers/preview/preview-webview.ts b/apps/vscode/src/providers/preview/preview-webview.ts index cfa78798..7407b274 100644 --- a/apps/vscode/src/providers/preview/preview-webview.ts +++ b/apps/vscode/src/providers/preview/preview-webview.ts @@ -51,7 +51,7 @@ export class QuartoPreviewWebviewManager extends QuartoWebviewManager< this.activeView_.setOnError(handler); } } - public getZoomLevelConfig() : "auto" | number { + public getZoomLevelConfig(): "auto" | number { return this.context.globalState.get<"auto" | number>(kQuarotPreviewZoomLevel, "auto"); } } diff --git a/apps/vscode/src/providers/render.ts b/apps/vscode/src/providers/render.ts index c9b3eb76..3b944d62 100644 --- a/apps/vscode/src/providers/render.ts +++ b/apps/vscode/src/providers/render.ts @@ -31,10 +31,10 @@ import { documentFrontMatterYaml } from "../markdown/document"; import { QuickPickItemKind } from "vscode"; import { Uri } from "vscode"; -export function activateRender(quartoContext: QuartoContext, engine: MarkdownEngine) : Command[] { +export function activateRender(quartoContext: QuartoContext, engine: MarkdownEngine): Command[] { // establish if we should include the typst command - // indicate that its okay to show + // indicate that its okay to show if (quartoContext.available && semver.gte(quartoContext.version, "1.4.388")) { commands.executeCommand( "setContext", @@ -80,8 +80,7 @@ export interface FormatQuickPickItem extends QuickPickItem { class RenderDocumentCommand extends RenderCommand - implements Command -{ + implements Command { constructor(quartoContext: QuartoContext, private readonly engine_: MarkdownEngine) { super(quartoContext); } @@ -98,7 +97,7 @@ class RenderDocumentCommand extends RenderCommand await targetEditor.activate(); } await commands.executeCommand("workbench.action.files.save"); - + // kill any existing terminal const kQuartoRenderTitle = "Quarto Render"; await killTerminal(kQuartoRenderTitle); @@ -108,7 +107,7 @@ class RenderDocumentCommand extends RenderCommand if (format === undefined) { return; } - + // create new terminal const target = targetEditor.document.uri; const env = await terminalEnv(target); @@ -122,7 +121,7 @@ class RenderDocumentCommand extends RenderCommand cmd.push(format); } await sendTerminalCommand(terminal, env, this.quartoContext(), cmd); - + // focus the editor (sometimes the terminal steals focus) if (!isNotebook(targetEditor.document)) { await targetEditor.activate(); @@ -134,8 +133,8 @@ class RenderDocumentCommand extends RenderCommand private async resolveFormat(targetEditor: QuartoEditor) { return new Promise((resolve) => { - - const frontMatter = targetEditor.notebook + + const frontMatter = targetEditor.notebook ? targetEditor.notebook.cellAt(0)?.document.getText() || "" : documentFrontMatterYaml(this.engine_, targetEditor.document); @@ -203,7 +202,7 @@ class RenderDocumentCommand extends RenderCommand } }); } - + } @@ -212,7 +211,7 @@ class RenderProjectCommand extends RenderCommand implements Command { public readonly id = RenderProjectCommand.id; constructor(quartoContext: QuartoContext, - private readonly engine_: MarkdownEngine) { + private readonly engine_: MarkdownEngine) { super(quartoContext); } @@ -228,7 +227,7 @@ class RenderProjectCommand extends RenderCommand implements Command { projectDir = Uri.file(docProjectDir); } } - + // if we didn't find it yet use the workspace if (!projectDir && workspace.workspaceFolders) { for (const folder of workspace.workspaceFolders) { @@ -239,42 +238,42 @@ class RenderProjectCommand extends RenderCommand implements Command { } } - + // render if we have a project dir if (projectDir) { - - // kill any existing terminal - const kQuartoRenderTitle = "Quarto Render"; - await killTerminal(kQuartoRenderTitle); - - // determine format - const format = await this.resolveFormat(projectDir); - if (format === undefined) { - return; - } - - // create new terminal - const env = await terminalEnv(projectDir); - const options = terminalOptions(kQuartoRenderTitle, projectDir, env); - const terminal = window.createTerminal(options); - - // build terminal command and send it - const cmd = terminalCommand("render", this.quartoContext()); - if (format !== "default") { + + // kill any existing terminal + const kQuartoRenderTitle = "Quarto Render"; + await killTerminal(kQuartoRenderTitle); + + // determine format + const format = await this.resolveFormat(projectDir); + if (format === undefined) { + return; + } + + // create new terminal + const env = await terminalEnv(projectDir); + const options = terminalOptions(kQuartoRenderTitle, projectDir, env); + const terminal = window.createTerminal(options); + + // build terminal command and send it + const cmd = terminalCommand("render", this.quartoContext()); + if (format !== "default") { cmd.push("--to"); cmd.push(format); - } - await sendTerminalCommand(terminal, env, this.quartoContext(), cmd); + } + await sendTerminalCommand(terminal, env, this.quartoContext(), cmd); } else { // no project found! window.showInformationMessage("No project available to render."); } } - private async resolveFormat(projectDir: Uri) : Promise { + private async resolveFormat(projectDir: Uri): Promise { return new Promise(async (resolve) => { const config = await quartoProjectConfig(this.quartoContext().runQuarto, projectDir.fsPath); - if (config?.config.project.type === "book" && typeof(config?.config.format) === "object") { + if (config?.config.project.type === "book" && typeof (config?.config.format) === "object") { const formats = Object.keys(config?.config.format); if (formats.length > 1) { const quickPick = window.createQuickPick(); @@ -316,6 +315,6 @@ class RenderProjectCommand extends RenderCommand implements Command { resolve("default"); } }); - + } } diff --git a/apps/vscode/src/providers/text-format.ts b/apps/vscode/src/providers/text-format.ts index bfc512c6..3b9a511e 100644 --- a/apps/vscode/src/providers/text-format.ts +++ b/apps/vscode/src/providers/text-format.ts @@ -63,7 +63,7 @@ class ToggleCommand implements Command { const shift = shifts .map(([pos, s]) => selection.start.line === pos.line && - selection.start.character >= pos.character + selection.start.character >= pos.character ? s : 0 ) diff --git a/apps/vscode/src/providers/walkthrough.ts b/apps/vscode/src/providers/walkthrough.ts index 7fc15fee..3d7bbd5b 100644 --- a/apps/vscode/src/providers/walkthrough.ts +++ b/apps/vscode/src/providers/walkthrough.ts @@ -35,7 +35,7 @@ class VerifyInstallationCommand implements Command { private static readonly id = "quarto.verifyInstallation"; public readonly id = VerifyInstallationCommand.id; - constructor(private readonly quartoContext_: QuartoContext) {} + constructor(private readonly quartoContext_: QuartoContext) { } async execute(): Promise { if (this.quartoContext_.available) { @@ -53,7 +53,7 @@ class WalkthroughNewDocumentCommand implements Command { private static readonly id = "quarto.walkthrough.newDocument"; public readonly id = WalkthroughNewDocumentCommand.id; - constructor(private readonly host_: ExtensionHost) {} + constructor(private readonly host_: ExtensionHost) { } async execute(): Promise { const saveDir = defaultSaveDir(); diff --git a/apps/vscode/src/providers/webview.ts b/apps/vscode/src/providers/webview.ts index 178f8e52..54e1005f 100644 --- a/apps/vscode/src/providers/webview.ts +++ b/apps/vscode/src/providers/webview.ts @@ -93,7 +93,7 @@ export class QuartoWebviewManager, S> { return !!this.activeView_ && this.activeView_.webviewPanel().visible; } - protected onViewStateChanged() {} + protected onViewStateChanged() { } private resolveOnShow() { if (this.onShow_) { @@ -238,7 +238,7 @@ export abstract class QuartoWebview extends Disposable { "codicon", "codicon.ttf", ]); - + return /* html */ ` @@ -247,9 +247,8 @@ export abstract class QuartoWebview extends Disposable { { +export async function activateZotero(context: ExtensionContext, lspClient: LanguageClient): Promise { // establish zotero connection const lspRequest = lspClientTransport(lspClient); - const zotero = editorZoteroJsonRpcServer(lspRequest); + const zotero = editorZoteroJsonRpcServer(lspRequest); // set quarto config for back end await syncZoteroConfig(context, zotero); @@ -44,7 +44,7 @@ export async function activateZotero(context: ExtensionContext, lspClient: Langu commands.push(new ZoteroConfigureLibraryCommand(kZoteroConfigureLibrary, context, zotero)); commands.push(new ZoteroSyncWebLibraryCommand(kZoteroSyncWebLibrary, context, zotero)); commands.push(new ZoteroUnauthorizedCommand(kZoteroUnauthorized, context, zotero)); - + // return commands return commands; } @@ -65,12 +65,12 @@ async function syncZoteroConfig(context: ExtensionContext, zotero: ZoteroServer) // if this isn't a retry then provide an initial delay (for the lsp to be ready) if (retry === undefined) { await sleep(500); - // if this is our final retry then bail + // if this is our final retry then bail } else if (retry === 5) { return; } const zoteroConfig = workspace.getConfiguration(kZoteroConfig); - const type = zoteroConfig.get<"none"|"local"|"web">(kLibrary, "local"); + const type = zoteroConfig.get<"none" | "local" | "web">(kLibrary, "local"); const dataDir = zoteroConfig.get(kDataDir, ""); const apiKey = await safeReadZoteroApiKey(context); try { @@ -79,11 +79,11 @@ async function syncZoteroConfig(context: ExtensionContext, zotero: ZoteroServer) dataDir, apiKey }); - } catch(error) { + } catch (error) { const message = error instanceof Error ? error.message : JSON.stringify(error); console.log("Error setting zotero library config: " + message); setTimeout(() => setLspLibraryConfig((retry || 0) + 1), 1000); - } + } }; await setLspLibraryConfig(); @@ -100,15 +100,15 @@ async function syncZoteroConfig(context: ExtensionContext, zotero: ZoteroServer) // monitor changes to configuration context.subscriptions.push(workspace.onDidChangeConfiguration(async (e) => { - + // sync changes to base config - if (e.affectsConfiguration(kZoteroLibrary) || - e.affectsConfiguration(kZoteroDataDir)) { + if (e.affectsConfiguration(kZoteroLibrary) || + e.affectsConfiguration(kZoteroDataDir)) { // if we are switching to web then prompt for an api key if we don't have one const zoteroConfig = workspace.getConfiguration(kZoteroConfig); - if (zoteroConfig.get(kLibrary) === "web" && - !(await safeReadZoteroApiKey(context))) { + if (zoteroConfig.get(kLibrary) === "web" && + !(await safeReadZoteroApiKey(context))) { await commands.executeCommand(kZoteroConfigureLibrary); } else { await setLspLibraryConfig(); @@ -119,11 +119,11 @@ async function syncZoteroConfig(context: ExtensionContext, zotero: ZoteroServer) if (e.affectsConfiguration(kZoteroGroupLibraries)) { // read updated library list const zoteroConfig = workspace.getConfiguration(kZoteroConfig); - const updatedGroupLibraries = zoteroConfig.get(kGroupLibraries, []); - + const updatedGroupLibraries = zoteroConfig.get(kGroupLibraries, []); + // sync if we are in web mode and there are new libraries added - if (zoteroConfig.get(kLibrary) === "web" && - updatedGroupLibraries.length > groupLibraries.length) { + if (zoteroConfig.get(kLibrary) === "web" && + updatedGroupLibraries.length > groupLibraries.length) { const apiKey = await safeReadZoteroApiKey(context); if (apiKey) { await syncWebLibraries(apiKey); @@ -139,9 +139,9 @@ async function syncZoteroConfig(context: ExtensionContext, zotero: ZoteroServer) // proxy for zotero requests that: // (a) forwards the currently configured collections (group libraries) // (b) checks for unauthorized errors and prompts for re-authorization -export function zoteroLspProxy(lspRequest: JsonRpcRequestTransport){ +export function zoteroLspProxy(lspRequest: JsonRpcRequestTransport) { - const zoteroLsp = editorZoteroJsonRpcServer(lspRequest); + const zoteroLsp = editorZoteroJsonRpcServer(lspRequest); const handleZoteroResult = (result: ZoteroResult) => { if (result.status === 'notfound' && result.unauthorized) { @@ -154,7 +154,7 @@ export function zoteroLspProxy(lspRequest: JsonRpcRequestTransport){ const fileCollections = [...collections]; if (fileCollections.length === 0) { const zoteroConfig = workspace.getConfiguration( - "quarto.zotero", + "quarto.zotero", file ? Uri.file(file) : null ); const groupLibraries = zoteroConfig.get("groupLibraries", []); @@ -167,7 +167,7 @@ export function zoteroLspProxy(lspRequest: JsonRpcRequestTransport){ }; return zoteroServerMethods({ - + ...zoteroLsp, getCollections: async ( @@ -175,27 +175,27 @@ export function zoteroLspProxy(lspRequest: JsonRpcRequestTransport){ collections: string[], cached: ZoteroCollectionSpec[], useCache: boolean, - ) : Promise => { + ): Promise => { return handleZoteroResult( await zoteroLsp.getCollections( - file, - collectionsForFile(collections, file), - cached, + file, + collectionsForFile(collections, file), + cached, useCache ) ); }, - getLibraryNames: async () : Promise => { + getLibraryNames: async (): Promise => { return handleZoteroResult( await zoteroLsp.getLibraryNames() ); }, - - getActiveCollectionSpecs: async (file: string | null, collections: string[]) : Promise => { + + getActiveCollectionSpecs: async (file: string | null, collections: string[]): Promise => { return handleZoteroResult( await zoteroLsp.getActiveCollectionSpecs( - file, + file, collectionsForFile(collections, file) ) ); @@ -209,33 +209,33 @@ class ZoteroConfigureLibraryCommand implements Command { public readonly id: string, private readonly context: ExtensionContext, private readonly zotero: ZoteroServer - ) {} + ) { } async execute() { const inputBox = window.createInputBox(); inputBox.title = "Connect Zotero Web Library"; inputBox.prompt = "Provide a Zotero Web API key to enable support for Zotero citations in " + - "the Quarto Visual Editor. You can generate keys at https://www.zotero.org/settings/keys"; - inputBox.password = true; - inputBox.ignoreFocusOut = true; + "the Quarto Visual Editor. You can generate keys at https://www.zotero.org/settings/keys"; + inputBox.password = true; + inputBox.ignoreFocusOut = true; inputBox.placeholder = "Zotero Web API Key"; inputBox.onDidAccept(async () => { - + // get key const apiKey = inputBox.value.trim(); // helper to save it const saveApiKey = async () => { - await this.context.secrets.store(kQuartoZoteroWebApiKey,apiKey); + await this.context.secrets.store(kQuartoZoteroWebApiKey, apiKey); inputBox.hide(); }; if (apiKey) { const valid = await zoteroValidateApiKey(apiKey); if (!valid) { - inputBox.validationMessage = "The API key you entered could not be validated with the Zotero web service. " + - "Please ensure that you have entered the key correctly and that it is currently valid."; + inputBox.validationMessage = "The API key you entered could not be validated with the Zotero web service. " + + "Please ensure that you have entered the key correctly and that it is currently valid."; } else { // save the secret and notify the server await saveApiKey(); @@ -245,7 +245,7 @@ class ZoteroConfigureLibraryCommand implements Command { } } else { await saveApiKey(); - } + } }); inputBox.onDidChangeValue(() => { inputBox.validationMessage = ""; @@ -260,7 +260,7 @@ class ZoteroSyncWebLibraryCommand implements Command { public readonly id: string, private readonly context: ExtensionContext, private readonly zotero: ZoteroServer - ) {} + ) { } async execute() { const apiKey = await safeReadZoteroApiKey(this.context); @@ -269,10 +269,11 @@ class ZoteroSyncWebLibraryCommand implements Command { } else { const result = await window.showInformationMessage( "Zotero Web Library Not Configured", - { - modal: true, + { + modal: true, detail: `You do not currently have a Zotero web library configured.` + - `Do you want to configure a web library now?` }, + `Do you want to configure a web library now?` + }, "Yes", "No" ); @@ -288,17 +289,18 @@ class ZoteroUnauthorizedCommand implements Command { public readonly id: string, private readonly context: ExtensionContext, private readonly zotero: ZoteroServer - ) {} + ) { } async execute() { const kYes = "Configure Zotero API Key"; - const kNo = "Disable Zotero Web Library"; + const kNo = "Disable Zotero Web Library"; const result = await window.showInformationMessage( "Zotero API Key Unauthorized", - { - modal: true, + { + modal: true, detail: `Your Zotero API key is no longer authorized. ` + - `Do you want to configure a new API key now?` }, + `Do you want to configure a new API key now?` + }, kYes, kNo ); @@ -327,7 +329,7 @@ async function syncWebLibraries(apiKey: string) { } increment = increment || (progressRemaining * 0.1); progressRemaining -= increment; - progress.report( { message, increment }); + progress.report({ message, increment }); }, log() { // don't log in foreground sync @@ -341,7 +343,7 @@ async function syncWebLibraries(apiKey: string) { try { const zotero = await zoteroApi(apiKey, progressHandler); await zoteroSyncWebLibraries(zotero, progressHandler); - } catch(error) { + } catch (error) { if (!(error instanceof SyncCancelledError)) { const message = error instanceof Error ? error.message : JSON.stringify(error); window.showErrorMessage("Error occurred during sync: " + message); @@ -360,7 +362,7 @@ class SyncCancelledError extends Error { async function safeReadZoteroApiKey(context: ExtensionContext) { try { return await context.secrets.get(kQuartoZoteroWebApiKey); - } catch(error) { + } catch (error) { console.log("Error reading zotero api key"); return undefined; } diff --git a/apps/vscode/src/vdoc/languages.ts b/apps/vscode/src/vdoc/languages.ts index 4c5c99d6..b2e76c0c 100644 --- a/apps/vscode/src/vdoc/languages.ts +++ b/apps/vscode/src/vdoc/languages.ts @@ -34,7 +34,7 @@ export function embeddedLanguage(langauge: string) { } export function languageCanFormatDocument(language: EmbeddedLanguage) { - return language.canFormatDocument !== false; + return language.canFormatDocument !== false; } const kEmbededLanguages = [ @@ -97,7 +97,7 @@ function defineLanguage( id: string, options?: LanguageOptions ): EmbeddedLanguage { - + // lookup langauge const language = editorLanguage(id); if (!language) { diff --git a/apps/vscode/src/vdoc/vdoc-completion.ts b/apps/vscode/src/vdoc/vdoc-completion.ts index 3295699c..82c4cf49 100644 --- a/apps/vscode/src/vdoc/vdoc-completion.ts +++ b/apps/vscode/src/vdoc/vdoc-completion.ts @@ -18,10 +18,10 @@ import { EmbeddedLanguage } from "./languages"; import { adjustedPosition, unadjustedRange, VirtualDoc, virtualDocUri, withVirtualDocUri } from "./vdoc"; export async function vdocCompletions( - vdoc: VirtualDoc, - position: Position, + vdoc: VirtualDoc, + position: Position, trigger: string | undefined, - language: EmbeddedLanguage, + language: EmbeddedLanguage, parentUri: Uri ) { diff --git a/apps/vscode/src/vdoc/vdoc-content.ts b/apps/vscode/src/vdoc/vdoc-content.ts index 847c6f0d..716dc50b 100644 --- a/apps/vscode/src/vdoc/vdoc-content.ts +++ b/apps/vscode/src/vdoc/vdoc-content.ts @@ -40,9 +40,8 @@ export function virtualDocUriFromEmbeddedContent( virtualDocumentContents.set(originalUri, virtualDoc.content); // form uri - const vdocUriString = `${kQmdEmbeddedContent}://${ - virtualDoc.language - }/${encodeURIComponent(originalUri)}.${virtualDoc.language.extension}`; + const vdocUriString = `${kQmdEmbeddedContent}://${virtualDoc.language + }/${encodeURIComponent(originalUri)}.${virtualDoc.language.extension}`; const vdocUri = Uri.parse(vdocUriString); // return it diff --git a/apps/vscode/src/vdoc/vdoc-tempfile.ts b/apps/vscode/src/vdoc/vdoc-tempfile.ts index 08985806..3dc11b28 100644 --- a/apps/vscode/src/vdoc/vdoc-tempfile.ts +++ b/apps/vscode/src/vdoc/vdoc-tempfile.ts @@ -33,10 +33,10 @@ import { EmbeddedLanguage } from "./languages"; const languageVirtualDocs = new Map(); export async function virtualDocUriFromTempFile( - virtualDoc: VirtualDoc, - docPath: string, + virtualDoc: VirtualDoc, + docPath: string, local: boolean -) : Promise { +): Promise { // if this is local then create it alongside the docPath and return a cleanup // function to remove it when the action is completed. diff --git a/apps/vscode/src/vdoc/vdoc.ts b/apps/vscode/src/vdoc/vdoc.ts index d673758e..9287c67b 100644 --- a/apps/vscode/src/vdoc/vdoc.ts +++ b/apps/vscode/src/vdoc/vdoc.ts @@ -75,10 +75,10 @@ export function virtualDocForLanguage( function linesForLanguage(document: TextDocument, language: EmbeddedLanguage) { const lines: string[] = []; - for (let i = 0; i < document.lineCount; i++) { - lines.push(language.emptyLine || ""); - } - return lines; + for (let i = 0; i < document.lineCount; i++) { + lines.push(language.emptyLine || ""); + } + return lines; } function fillLinesFromBlock(lines: string[], document: TextDocument, block: Token) { @@ -92,13 +92,13 @@ function fillLinesFromBlock(lines: string[], document: TextDocument, block: Toke } function padLinesForLanguage(lines: string[], language: EmbeddedLanguage) { - for (let i=0; i<2; i++) { - lines.push(language.emptyLine || ""); + for (let i = 0; i < 2; i++) { + lines.push(language.emptyLine || ""); } } export function virtualDocForCode(code: string[], language: EmbeddedLanguage) { - + const lines = [...code]; if (language.inject) { @@ -111,12 +111,12 @@ export function virtualDocForCode(code: string[], language: EmbeddedLanguage) { }; } -export type VirtualDocAction = - "completion" | - "hover" | - "signature" | - "definition" | - "format" | +export type VirtualDocAction = + "completion" | + "hover" | + "signature" | + "definition" | + "format" | "statementRange"; export type VirtualDocUri = { uri: Uri, cleanup?: () => Promise }; @@ -132,10 +132,10 @@ export async function withVirtualDocUri(virtualDocUri: VirtualDocUri, f: (uri } export async function virtualDocUri( - virtualDoc: VirtualDoc, - parentUri: Uri, + virtualDoc: VirtualDoc, + parentUri: Uri, action: VirtualDocAction -) : Promise { +): Promise { // format and definition actions use a transient local vdoc // (so they can get project-specific paths and formatting config) From 7e8109e34007be537f710ea66dd4c3d3d3b3307f Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Mon, 28 Oct 2024 09:51:00 -0600 Subject: [PATCH 2/3] Apply default formatting to `.json` files --- apps/vscode/.eslintrc.json | 38 +++++++++++-------------- apps/vscode/.vscode/extensions.json | 8 ++---- apps/vscode/.vscode/launch.json | 30 +++++++++---------- apps/vscode/.vscode/settings.json | 20 ++++++------- apps/vscode/.vscode/tasks.json | 32 ++++++++++----------- apps/vscode/language-configuration.json | 2 +- apps/vscode/tsconfig.json | 28 +++++++++--------- 7 files changed, 72 insertions(+), 86 deletions(-) diff --git a/apps/vscode/.eslintrc.json b/apps/vscode/.eslintrc.json index f9b22b79..5dfecab7 100644 --- a/apps/vscode/.eslintrc.json +++ b/apps/vscode/.eslintrc.json @@ -1,24 +1,18 @@ { - "root": true, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module" - }, - "plugins": [ - "@typescript-eslint" - ], - "rules": { - "@typescript-eslint/naming-convention": "warn", - "@typescript-eslint/semi": "warn", - "curly": "warn", - "eqeqeq": "warn", - "no-throw-literal": "warn", - "semi": "off" - }, - "ignorePatterns": [ - "out", - "dist", - "**/*.d.ts" - ] + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "plugins": ["@typescript-eslint"], + "rules": { + "@typescript-eslint/naming-convention": "warn", + "@typescript-eslint/semi": "warn", + "curly": "warn", + "eqeqeq": "warn", + "no-throw-literal": "warn", + "semi": "off" + }, + "ignorePatterns": ["out", "dist", "**/*.d.ts"] } diff --git a/apps/vscode/.vscode/extensions.json b/apps/vscode/.vscode/extensions.json index 3ac9aeb6..c0a2258b 100644 --- a/apps/vscode/.vscode/extensions.json +++ b/apps/vscode/.vscode/extensions.json @@ -1,7 +1,5 @@ { - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "dbaeumer.vscode-eslint" - ] + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": ["dbaeumer.vscode-eslint"] } diff --git a/apps/vscode/.vscode/launch.json b/apps/vscode/.vscode/launch.json index 292909a7..6b951904 100644 --- a/apps/vscode/.vscode/launch.json +++ b/apps/vscode/.vscode/launch.json @@ -3,27 +3,23 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "0.2.0", - "configurations": [ - { - "name": "Run Extension", - "type": "extensionHost", - "request": "launch", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}" - ], - "outFiles": [ - "${workspaceFolder}/out/**/*.js" - ], - "preLaunchTask": "${defaultBuildTask}" - }, - { + "version": "0.2.0", + "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "args": ["--extensionDevelopmentPath=${workspaceFolder}"], + "outFiles": ["${workspaceFolder}/out/**/*.js"], + "preLaunchTask": "${defaultBuildTask}" + }, + { "type": "node", "request": "attach", "name": "Attach to Server", "port": 6009, "restart": true, "outFiles": ["${workspaceRoot}/out/**/*.js"] - }, - ] + } + ] } diff --git a/apps/vscode/.vscode/settings.json b/apps/vscode/.vscode/settings.json index f0d3fabc..d2840592 100644 --- a/apps/vscode/.vscode/settings.json +++ b/apps/vscode/.vscode/settings.json @@ -1,13 +1,13 @@ // Place your settings in this file to overwrite default and user settings. { - "files.exclude": { - "out": false // set this to true to hide the "out" folder with the compiled JS files - }, - "search.exclude": { - "out": true // set this to false to include "out" folder in search results - }, - // Turn off tsc task auto detection since we have the necessary tasks as npm scripts - "typescript.tsc.autoDetect": "off", + "files.exclude": { + "out": false // set this to true to hide the "out" folder with the compiled JS files + }, + "search.exclude": { + "out": true // set this to false to include "out" folder in search results + }, + // Turn off tsc task auto detection since we have the necessary tasks as npm scripts + "typescript.tsc.autoDetect": "off", - "editor.tabSize": 2 -} \ No newline at end of file + "editor.tabSize": 2 +} diff --git a/apps/vscode/.vscode/tasks.json b/apps/vscode/.vscode/tasks.json index 3b17e53b..078ff7e0 100644 --- a/apps/vscode/.vscode/tasks.json +++ b/apps/vscode/.vscode/tasks.json @@ -1,20 +1,20 @@ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format { - "version": "2.0.0", - "tasks": [ - { - "type": "npm", - "script": "watch", - "problemMatcher": "$tsc-watch", - "isBackground": true, - "presentation": { - "reveal": "never" - }, - "group": { - "kind": "build", - "isDefault": true - } - } - ] + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "watch", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] } diff --git a/apps/vscode/language-configuration.json b/apps/vscode/language-configuration.json index 6d5f41cd..80c61071 100644 --- a/apps/vscode/language-configuration.json +++ b/apps/vscode/language-configuration.json @@ -1,7 +1,7 @@ { "comments": { // symbols used for start and end a block comment. Remove this entry if your language does not support block comments - "blockComment": [""], + "blockComment": [""] }, // symbols used as brackets "brackets": [ diff --git a/apps/vscode/tsconfig.json b/apps/vscode/tsconfig.json index d67396a3..b4379476 100644 --- a/apps/vscode/tsconfig.json +++ b/apps/vscode/tsconfig.json @@ -1,17 +1,15 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "ES2021", - "outDir": "out", - "lib": [ - "ES2021" - ], - "sourceMap": true, - "strict": true /* enable all strict type-checking options */ - /* Additional Checks */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - }, - "extends": "tsconfig/base.json" + "compilerOptions": { + "module": "commonjs", + "target": "ES2021", + "outDir": "out", + "lib": ["ES2021"], + "sourceMap": true, + "strict": true /* enable all strict type-checking options */ + /* Additional Checks */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + }, + "extends": "tsconfig/base.json" } From 67bbd89d48d85cb3770f0fc95938cd8e703fcfdd Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Tue, 29 Oct 2024 14:24:20 -0600 Subject: [PATCH 3/3] Apply more settings for final newlines and whitespace --- .vscode/settings.json | 7 +++++-- apps/vscode/.gitignore | 2 +- apps/vscode/.vscodeignore | 1 - apps/vscode/.yarnrc | 2 +- apps/vscode/README.md | 6 ++---- apps/vscode/assets/www/editor/.gitignore | 2 +- apps/vscode/languages/dot/dot.configuration.json | 2 +- .../languages/mermaid/mermaid.configuration.json | 2 +- .../languages/mermaid/mermaid.tmLanguage.json | 2 +- .../vscode/languages/typst/typst.configuration.json | 2 +- apps/vscode/src/@types/hooks.d.ts | 3 --- apps/vscode/src/core/config.ts | 4 ++-- apps/vscode/src/core/hover.ts | 1 - apps/vscode/src/core/python.ts | 1 - apps/vscode/src/core/terminal.ts | 1 - apps/vscode/src/core/workspace.ts | 2 +- apps/vscode/src/host/index.ts | 2 +- apps/vscode/src/lsp/client.ts | 2 -- apps/vscode/src/main.ts | 3 +-- apps/vscode/src/providers/assist/render-assist.ts | 2 +- apps/vscode/src/providers/create/create.ts | 1 - apps/vscode/src/providers/deno-config.ts | 6 ------ apps/vscode/src/providers/editor/codeview.ts | 4 ++-- apps/vscode/src/providers/editor/connection.ts | 2 +- apps/vscode/src/providers/editor/editor.ts | 10 +++++----- apps/vscode/src/providers/editor/images.ts | 1 - apps/vscode/src/providers/editor/prefs.ts | 1 - apps/vscode/src/providers/editor/sync.ts | 13 ++++++------- apps/vscode/src/providers/editor/toggle.ts | 2 +- apps/vscode/src/providers/preview/preview-env.ts | 2 +- apps/vscode/src/providers/zotero/zotero.ts | 4 ++-- apps/vscode/src/vdoc/vdoc-completion.ts | 2 +- apps/vscode/src/vdoc/vdoc-tempfile.ts | 4 ++-- 33 files changed, 41 insertions(+), 60 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 15988045..f5aa9faf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,8 @@ "editor.formatOnSave": true }, "typescript.tsdk": "node_modules/typescript/lib", - "editor.tabSize": 2 -} \ No newline at end of file + "editor.tabSize": 2, + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": true +} diff --git a/apps/vscode/.gitignore b/apps/vscode/.gitignore index d3ba603c..808e1d34 100644 --- a/apps/vscode/.gitignore +++ b/apps/vscode/.gitignore @@ -1,2 +1,2 @@ out/ -*.vsix \ No newline at end of file +*.vsix diff --git a/apps/vscode/.vscodeignore b/apps/vscode/.vscodeignore index 8c3e80d2..62b702c8 100644 --- a/apps/vscode/.vscodeignore +++ b/apps/vscode/.vscodeignore @@ -10,4 +10,3 @@ src/** **/*.map **/*.ts *.vsix - diff --git a/apps/vscode/.yarnrc b/apps/vscode/.yarnrc index f757a6ac..4f14322d 100644 --- a/apps/vscode/.yarnrc +++ b/apps/vscode/.yarnrc @@ -1 +1 @@ ---ignore-engines true \ No newline at end of file +--ignore-engines true diff --git a/apps/vscode/README.md b/apps/vscode/README.md index b507ad6d..89bdec6d 100644 --- a/apps/vscode/README.md +++ b/apps/vscode/README.md @@ -21,7 +21,6 @@ The easiest way to install is directly from within VS Code (search extensions fo You can also install from the [VS Code Extension Marketplace](https://marketplace.visualstudio.com/items?itemName=quarto.quarto), the [Open VSX Registry](https://open-vsx.org/extension/quarto/quarto) or directly from a [VISX extension file](#visx-install). - ## Render and Preview The Quarto VS Code extension includes commands and keyboard shortcuts for rendering Quarto documents (both standalone and within websites or books). After rendering, `quarto preview` is used behind the scenes to provide a preview pane within VS Code alongside your document: @@ -44,7 +43,7 @@ When you execute **Preview Format**, you'll see a quick pick list of formats to ![](https://quarto.org/docs/tools/images/vscode-preview-format.png) -After previewing a different format, the **Quarto: Preview** command and Ctrl+Shift+K keyboard shortcut will be automatically rebound to the newly selected format for the duration of the current preview. To switch back to previewing the original format, use **Quarto: Preview Format** command again. +After previewing a different format, the **Quarto: Preview** command and Ctrl+Shift+K keyboard shortcut will be automatically rebound to the newly selected format for the duration of the current preview. To switch back to previewing the original format, use **Quarto: Preview Format** command again. > Embedded preview is currently supported for HTML and PDF based formats (including `revealjs` and `beamer` slideshows). However, for Word and other formats you need to use an appropriate external program to preview the output. @@ -64,7 +63,7 @@ However, you can configure the Quarto extension to automatically render whenever You might also want to control this behavior on a per-document or per-project basis. If you include the `editor: render-on-save` option in your document or project YAML it will supersede whatever your VS Code setting is. For example: -``` yaml +```yaml editor: render-on-save: true ``` @@ -75,7 +74,6 @@ If you prefer to use an external browser for preview (or have no preview trigger ![](https://quarto.org/docs/tools/images/vscode-preview-settings.png) - ## Code Cells There are a variety of tools that make it easier to edit and execute diff --git a/apps/vscode/assets/www/editor/.gitignore b/apps/vscode/assets/www/editor/.gitignore index d51579d1..a4e42b6d 100644 --- a/apps/vscode/assets/www/editor/.gitignore +++ b/apps/vscode/assets/www/editor/.gitignore @@ -1,2 +1,2 @@ index.js -style.css \ No newline at end of file +style.css diff --git a/apps/vscode/languages/dot/dot.configuration.json b/apps/vscode/languages/dot/dot.configuration.json index 4051e9f2..305f6347 100644 --- a/apps/vscode/languages/dot/dot.configuration.json +++ b/apps/vscode/languages/dot/dot.configuration.json @@ -20,4 +20,4 @@ ")" ] ] -} \ No newline at end of file +} diff --git a/apps/vscode/languages/mermaid/mermaid.configuration.json b/apps/vscode/languages/mermaid/mermaid.configuration.json index 086c6e3b..dfd0fab0 100644 --- a/apps/vscode/languages/mermaid/mermaid.configuration.json +++ b/apps/vscode/languages/mermaid/mermaid.configuration.json @@ -16,4 +16,4 @@ ")" ] ] -} \ No newline at end of file +} diff --git a/apps/vscode/languages/mermaid/mermaid.tmLanguage.json b/apps/vscode/languages/mermaid/mermaid.tmLanguage.json index 958b1d58..717f9721 100644 --- a/apps/vscode/languages/mermaid/mermaid.tmLanguage.json +++ b/apps/vscode/languages/mermaid/mermaid.tmLanguage.json @@ -883,4 +883,4 @@ } }, "scopeName": "source.mmd" -} \ No newline at end of file +} diff --git a/apps/vscode/languages/typst/typst.configuration.json b/apps/vscode/languages/typst/typst.configuration.json index 4051e9f2..305f6347 100644 --- a/apps/vscode/languages/typst/typst.configuration.json +++ b/apps/vscode/languages/typst/typst.configuration.json @@ -20,4 +20,4 @@ ")" ] ] -} \ No newline at end of file +} diff --git a/apps/vscode/src/@types/hooks.d.ts b/apps/vscode/src/@types/hooks.d.ts index 99ae993e..66abfa90 100644 --- a/apps/vscode/src/@types/hooks.d.ts +++ b/apps/vscode/src/@types/hooks.d.ts @@ -72,6 +72,3 @@ declare module 'positron' { readonly previewPanel: PreviewPanel; } } - - - diff --git a/apps/vscode/src/core/config.ts b/apps/vscode/src/core/config.ts index bf89a409..ad782fff 100644 --- a/apps/vscode/src/core/config.ts +++ b/apps/vscode/src/core/config.ts @@ -19,8 +19,8 @@ export async function safeUpdateConfig(updateFn: () => Promise) { try { await updateFn(); } catch (error) { - // if the user's settings.json file is corrupt/invalid this + // if the user's settings.json file is corrupt/invalid this // will throw an exception and prevent loading of the extension console.log("Unexpected error writing config (settings.json may be corrupt)"); } -} \ No newline at end of file +} diff --git a/apps/vscode/src/core/hover.ts b/apps/vscode/src/core/hover.ts index a05608b3..b0825488 100644 --- a/apps/vscode/src/core/hover.ts +++ b/apps/vscode/src/core/hover.ts @@ -57,4 +57,3 @@ export async function getSignatureHelpHover( triggerCharacter ); } - diff --git a/apps/vscode/src/core/python.ts b/apps/vscode/src/core/python.ts index 489e374e..56c2bd85 100644 --- a/apps/vscode/src/core/python.ts +++ b/apps/vscode/src/core/python.ts @@ -71,4 +71,3 @@ export function pythonIsCondaEnv(python: string) { return false; } } - diff --git a/apps/vscode/src/core/terminal.ts b/apps/vscode/src/core/terminal.ts index 997d2887..40410b29 100644 --- a/apps/vscode/src/core/terminal.ts +++ b/apps/vscode/src/core/terminal.ts @@ -184,4 +184,3 @@ function requiredTerminalDelay(env?: TerminalEnv): number { return 0; } } - diff --git a/apps/vscode/src/core/workspace.ts b/apps/vscode/src/core/workspace.ts index dc8ad8fd..0ca69b93 100644 --- a/apps/vscode/src/core/workspace.ts +++ b/apps/vscode/src/core/workspace.ts @@ -22,4 +22,4 @@ export function activeWorkspaceFolder(uri?: Uri): WorkspaceFolder | undefined { ? workspace.workspaceFolders[0] : undefined; return workspaceFolder; -} \ No newline at end of file +} diff --git a/apps/vscode/src/host/index.ts b/apps/vscode/src/host/index.ts index 0f8295de..bfbd8bf5 100644 --- a/apps/vscode/src/host/index.ts +++ b/apps/vscode/src/host/index.ts @@ -105,4 +105,4 @@ function defaultExtensionHost(): ExtensionHost { }, createPreviewPanel, }; -} \ No newline at end of file +} diff --git a/apps/vscode/src/lsp/client.ts b/apps/vscode/src/lsp/client.ts index c527b2d1..c54753eb 100644 --- a/apps/vscode/src/lsp/client.ts +++ b/apps/vscode/src/lsp/client.ts @@ -349,5 +349,3 @@ function isWithinYamlComment(doc: TextDocument, pos: Position) { const line = doc.lineAt(pos.line).text; return !!line.match(/^\s*#\s*\| /); } - - diff --git a/apps/vscode/src/main.ts b/apps/vscode/src/main.ts index 4371c4e5..dfedbba4 100644 --- a/apps/vscode/src/main.ts +++ b/apps/vscode/src/main.ts @@ -90,7 +90,7 @@ export async function activate(context: vscode.ExtensionContext) { const editorCommands = activateEditor(context, host, quartoContext, lspClient, engine); commands.push(...editorCommands); - // zotero + // zotero const zoteroCommands = await activateZotero(context, lspClient); commands.push(...zoteroCommands); @@ -130,4 +130,3 @@ export async function activate(context: vscode.ExtensionContext) { export async function deactivate() { return deactivateLsp(); } - diff --git a/apps/vscode/src/providers/assist/render-assist.ts b/apps/vscode/src/providers/assist/render-assist.ts index 21b918ec..a067d969 100644 --- a/apps/vscode/src/providers/assist/render-assist.ts +++ b/apps/vscode/src/providers/assist/render-assist.ts @@ -64,7 +64,7 @@ export function renderWebviewHtml(webview: Webview, extensionUri: Uri) { - + Quarto Lens diff --git a/apps/vscode/src/providers/create/create.ts b/apps/vscode/src/providers/create/create.ts index 1de82605..8e2a1291 100644 --- a/apps/vscode/src/providers/create/create.ts +++ b/apps/vscode/src/providers/create/create.ts @@ -41,4 +41,3 @@ export async function activateCreate( ), ]; } - diff --git a/apps/vscode/src/providers/deno-config.ts b/apps/vscode/src/providers/deno-config.ts index 4188ff20..2fa972df 100644 --- a/apps/vscode/src/providers/deno-config.ts +++ b/apps/vscode/src/providers/deno-config.ts @@ -43,9 +43,3 @@ export function activateDenoConfig(context: ExtensionContext, engine: MarkdownEn workspace.onDidSaveTextDocument(ensureDenoConfig, null, context.subscriptions); } } - - - - - - diff --git a/apps/vscode/src/providers/editor/codeview.ts b/apps/vscode/src/providers/editor/codeview.ts index 1d08938c..c352e3b7 100644 --- a/apps/vscode/src/providers/editor/codeview.ts +++ b/apps/vscode/src/providers/editor/codeview.ts @@ -133,7 +133,7 @@ function lspCellYamlOptionsCompletions(context: CodeViewCompletionContext, lspRe }); // include language header (we offset cellEnd below accordingly) code.splice(context.cellBegin, 0, `{${context.language}}`); - // make request + // make request return lspRequest(kCodeViewGetCompletions, [{ ...context, code, @@ -285,4 +285,4 @@ function mdStringToMdContent(mdString: MarkdownString): MarkupContent { kind: MarkupKind.Markdown, value: mdString.value }; -} \ No newline at end of file +} diff --git a/apps/vscode/src/providers/editor/connection.ts b/apps/vscode/src/providers/editor/connection.ts index e5783280..7fc90685 100644 --- a/apps/vscode/src/providers/editor/connection.ts +++ b/apps/vscode/src/providers/editor/connection.ts @@ -176,4 +176,4 @@ function webviewPanelPostMessageTarget(webviewPanel: WebviewPanel): JsonRpcPostM }; } }; -} \ No newline at end of file +} diff --git a/apps/vscode/src/providers/editor/editor.ts b/apps/vscode/src/providers/editor/editor.ts index 52afddfa..7514cbe6 100644 --- a/apps/vscode/src/providers/editor/editor.ts +++ b/apps/vscode/src/providers/editor/editor.ts @@ -116,12 +116,12 @@ export class VisualEditorProvider implements CustomTextEditorProvider { engine: MarkdownEngine ): Disposable { - // setup request transport + // setup request transport const lspRequest = lspClientTransport(lspClient); // track edits in the active editor if its untitled. this enables us to recover the // content when we switch to an untitled document, which otherwise are just dropped - // on the floor by vscode + // on the floor by vscode context.subscriptions.push(workspace.onDidChangeTextDocument(e => { const doc = window.activeTextEditor?.document; if (doc && isQuartoDoc(doc) && doc.isUntitled && (doc.uri.toString() === e.document.uri.toString())) { @@ -326,7 +326,7 @@ export class VisualEditorProvider implements CustomTextEditorProvider { xref || sourcePos ); - // editor container implementation + // editor container implementation const host: VSCodeVisualEditorHost = { // editor is querying for context @@ -632,7 +632,7 @@ function visualEditorTracker(): VisualEditorTracker { try { return editor.webviewPanel.active || (includeVisible && editor.webviewPanel.visible); } catch (err) { - // we've seen activeEditors hold on to references to disposed editors (can't on the + // we've seen activeEditors hold on to references to disposed editors (can't on the // surface see how this would occur as we subscribe to dispose, but as an insurance // policy let's eat any exception that occurs, since a single zombie webviewPanel // would prevent rendering of other panels @@ -668,7 +668,7 @@ function focusTracker(webviewPanel: WebviewPanel, editor: VSCodeVisualEditor): D } }); - // periodically check for focus + // periodically check for focus const timer = setInterval(async () => { // update focus state hasFocus = await editor.isFocused(); diff --git a/apps/vscode/src/providers/editor/images.ts b/apps/vscode/src/providers/editor/images.ts index d92a2324..a2ecd467 100644 --- a/apps/vscode/src/providers/editor/images.ts +++ b/apps/vscode/src/providers/editor/images.ts @@ -129,4 +129,3 @@ export function documentImageResolver( } }; } - diff --git a/apps/vscode/src/providers/editor/prefs.ts b/apps/vscode/src/providers/editor/prefs.ts index 16cb6522..81345178 100644 --- a/apps/vscode/src/providers/editor/prefs.ts +++ b/apps/vscode/src/providers/editor/prefs.ts @@ -320,4 +320,3 @@ function writePerDocumentPrefs(document: TextDocument, prefs: PerDocumentPrefs) const storage = filePrefsStorage(document.uri.fsPath); writeFileSync(storage, JSON.stringify(prefs), { encoding: "utf8" }); } - diff --git a/apps/vscode/src/providers/editor/sync.ts b/apps/vscode/src/providers/editor/sync.ts index d2fbbb1c..f34fa2c7 100644 --- a/apps/vscode/src/providers/editor/sync.ts +++ b/apps/vscode/src/providers/editor/sync.ts @@ -21,11 +21,11 @@ import { isXRef, NavLocation, VSCodeVisualEditor, XRef } from "editor-types"; import { getWholeRange } from "../../core/doc"; -/* Strategy for managing synchronization of edits between source and visual mode. +/* Strategy for managing synchronization of edits between source and visual mode. -This is made more complicated by the fact that getting/setting visual editor markdown +This is made more complicated by the fact that getting/setting visual editor markdown is expensive (requires a pandoc round trip) so is throttled by 1 second. We also need -to guard against edits pinging back and forth (esp. w/ the requirement on flushing all +to guard against edits pinging back and forth (esp. w/ the requirement on flushing all pending edits on save) For the visual editor syncing to external changes: @@ -33,7 +33,7 @@ For the visual editor syncing to external changes: 1) Only accept external edits when NOT focused (once the visual editor is focused it is the definitive source of changes to the document) -2) These external edits are throttled by 1 second so we don't get constant (expensive) +2) These external edits are throttled by 1 second so we don't get constant (expensive) refreshing of the visual editor when users type in the text editor. For the visual editor propagating its own changes: @@ -65,9 +65,9 @@ export function editorSyncManager( navigation?: XRef | number ): EditorSyncManager { - // state: an update from the visual editor that we have yet to apply. we don't + // state: an update from the visual editor that we have yet to apply. we don't // apply these on every keystoke b/c they are expensive. we poll to apply these - // udpates periodically and also apply them immediately on save and when the + // udpates periodically and also apply them immediately on save and when the // visual editor instructs us to do so (e.g. when it loses focus) let pendingVisualEdit: unknown | undefined; @@ -208,4 +208,3 @@ async function updateWorkspaceDocument(document: TextDocument, markdown: string) updateDocument(editor, document, markdown); await workspace.applyEdit(edit); }; - diff --git a/apps/vscode/src/providers/editor/toggle.ts b/apps/vscode/src/providers/editor/toggle.ts index 95bb0545..b48a4213 100644 --- a/apps/vscode/src/providers/editor/toggle.ts +++ b/apps/vscode/src/providers/editor/toggle.ts @@ -76,7 +76,7 @@ export async function reopenEditorInSourceMode( // note pending switch to source VisualEditorProvider.recordPendingSwitchToSource(document); - // close editor (return immediately as if we don't then any + // close editor (return immediately as if we don't then any // rpc method that calls this wil result in an error b/c the webview // has been torn down by the time we return) commands.executeCommand('workbench.action.closeActiveEditor').then(async () => { diff --git a/apps/vscode/src/providers/preview/preview-env.ts b/apps/vscode/src/providers/preview/preview-env.ts index d56820c3..97815955 100644 --- a/apps/vscode/src/providers/preview/preview-env.ts +++ b/apps/vscode/src/providers/preview/preview-env.ts @@ -51,7 +51,7 @@ export class PreviewEnvManager { // eslint-disable-next-line @typescript-eslint/naming-convention QUARTO_LOG: this.outputFile_, - // eslint-disable-next-line @typescript-eslint/naming-convention + // eslint-disable-next-line @typescript-eslint/naming-convention QUARTO_RENDER_TOKEN: this.renderToken_, ...(await terminalEnv(uri)) diff --git a/apps/vscode/src/providers/zotero/zotero.ts b/apps/vscode/src/providers/zotero/zotero.ts index 32ad732e..1088ee30 100644 --- a/apps/vscode/src/providers/zotero/zotero.ts +++ b/apps/vscode/src/providers/zotero/zotero.ts @@ -222,7 +222,7 @@ class ZoteroConfigureLibraryCommand implements Command { inputBox.placeholder = "Zotero Web API Key"; inputBox.onDidAccept(async () => { - // get key + // get key const apiKey = inputBox.value.trim(); // helper to save it @@ -366,4 +366,4 @@ async function safeReadZoteroApiKey(context: ExtensionContext) { console.log("Error reading zotero api key"); return undefined; } -} \ No newline at end of file +} diff --git a/apps/vscode/src/vdoc/vdoc-completion.ts b/apps/vscode/src/vdoc/vdoc-completion.ts index 82c4cf49..84310c74 100644 --- a/apps/vscode/src/vdoc/vdoc-completion.ts +++ b/apps/vscode/src/vdoc/vdoc-completion.ts @@ -53,4 +53,4 @@ export async function vdocCompletions( return completion; }); -} \ No newline at end of file +} diff --git a/apps/vscode/src/vdoc/vdoc-tempfile.ts b/apps/vscode/src/vdoc/vdoc-tempfile.ts index 3dc11b28..8400a8c3 100644 --- a/apps/vscode/src/vdoc/vdoc-tempfile.ts +++ b/apps/vscode/src/vdoc/vdoc-tempfile.ts @@ -38,8 +38,8 @@ export async function virtualDocUriFromTempFile( local: boolean ): Promise { - // if this is local then create it alongside the docPath and return a cleanup - // function to remove it when the action is completed. + // if this is local then create it alongside the docPath and return a cleanup + // function to remove it when the action is completed. if (local || virtualDoc.language.localTempFile) { const ext = virtualDoc.language.extension; const vdocPath = path.join(path.dirname(docPath), `.vdoc.${ext}`);