diff --git a/extensions/vscode/src/api/types/configurations.test.ts b/extensions/vscode/src/api/types/configurations.test.ts index bcba28c28..efeb80e56 100644 --- a/extensions/vscode/src/api/types/configurations.test.ts +++ b/extensions/vscode/src/api/types/configurations.test.ts @@ -5,8 +5,12 @@ import { RConfig, PythonConfig, Configuration, + ContentType, UpdateConfigWithDefaults, UpdateAllConfigsWithDefaults, + isPythonContent, + isAPIContent, + isAppContent, } from "./configurations"; import { InterpreterDefaults } from "./interpreters"; import { @@ -98,6 +102,82 @@ describe("Configurations Types", () => { ); }); + describe("isPythonContent", () => { + test.each([ + ContentType.JUPYTER_NOTEBOOK, + ContentType.JUPYTER_VOILA, + ContentType.PYTHON_BOKEH, + ContentType.PYTHON_DASH, + ContentType.PYTHON_FASTAPI, + ContentType.PYTHON_FLASK, + ContentType.PYTHON_GRADIO, + ContentType.PYTHON_PANEL, + ContentType.PYTHON_SHINY, + ContentType.PYTHON_STREAMLIT, + ])("returns true for %s", (type) => { + expect(isPythonContent(type)).toBe(true); + }); + + test.each([ + ContentType.HTML, + ContentType.QUARTO, + ContentType.QUARTO_STATIC, + ContentType.QUARTO_SHINY, + ContentType.R_PLUMBER, + ContentType.R_SHINY, + ContentType.RMD, + ContentType.RMD_SHINY, + ContentType.UNKNOWN, + ])("returns false for %s", (type) => { + expect(isPythonContent(type)).toBe(false); + }); + }); + + describe("isAPIContent", () => { + test.each([ + ContentType.PYTHON_FLASK, + ContentType.PYTHON_FASTAPI, + ContentType.R_PLUMBER, + ])("returns true for %s", (type) => { + expect(isAPIContent(type)).toBe(true); + }); + + test.each([ + ContentType.HTML, + ContentType.PYTHON_SHINY, + ContentType.R_SHINY, + ContentType.QUARTO, + ContentType.UNKNOWN, + ])("returns false for %s", (type) => { + expect(isAPIContent(type)).toBe(false); + }); + }); + + describe("isAppContent", () => { + test.each([ + ContentType.PYTHON_SHINY, + ContentType.R_SHINY, + ContentType.PYTHON_BOKEH, + ContentType.PYTHON_DASH, + ContentType.PYTHON_GRADIO, + ContentType.PYTHON_PANEL, + ContentType.PYTHON_STREAMLIT, + ])("returns true for %s", (type) => { + expect(isAppContent(type)).toBe(true); + }); + + test.each([ + ContentType.HTML, + ContentType.PYTHON_FLASK, + ContentType.PYTHON_FASTAPI, + ContentType.R_PLUMBER, + ContentType.QUARTO, + ContentType.UNKNOWN, + ])("returns false for %s", (type) => { + expect(isAppContent(type)).toBe(false); + }); + }); + describe("UpdateAllConfigsWithDefaults", () => { test("updates all configs passed to it", () => { const multiConfigs: Configuration[] = []; diff --git a/extensions/vscode/src/api/types/configurations.ts b/extensions/vscode/src/api/types/configurations.ts index d381b9f6b..386f0d0d9 100644 --- a/extensions/vscode/src/api/types/configurations.ts +++ b/extensions/vscode/src/api/types/configurations.ts @@ -88,6 +88,50 @@ export const allValidContentTypes: ContentType[] = [ ContentType.RMD, ]; +export function isPythonContent(type: ContentType): boolean { + switch (type) { + case ContentType.JUPYTER_NOTEBOOK: + case ContentType.JUPYTER_VOILA: + case ContentType.PYTHON_BOKEH: + case ContentType.PYTHON_DASH: + case ContentType.PYTHON_FASTAPI: + case ContentType.PYTHON_FLASK: + case ContentType.PYTHON_GRADIO: + case ContentType.PYTHON_PANEL: + case ContentType.PYTHON_SHINY: + case ContentType.PYTHON_STREAMLIT: + return true; + default: + return false; + } +} + +export function isAPIContent(type: ContentType): boolean { + switch (type) { + case ContentType.PYTHON_FLASK: + case ContentType.PYTHON_FASTAPI: + case ContentType.R_PLUMBER: + return true; + default: + return false; + } +} + +export function isAppContent(type: ContentType): boolean { + switch (type) { + case ContentType.PYTHON_SHINY: + case ContentType.R_SHINY: + case ContentType.PYTHON_BOKEH: + case ContentType.PYTHON_DASH: + case ContentType.PYTHON_GRADIO: + case ContentType.PYTHON_PANEL: + case ContentType.PYTHON_STREAMLIT: + return true; + default: + return false; + } +} + export const contentTypeStrings = { [ContentType.HTML]: "serve pre-rendered HTML", [ContentType.JUPYTER_NOTEBOOK]: "render with Jupyter nbconvert",