diff --git a/web/src/containers/Studio/internal/helper.ts b/web/src/containers/Studio/internal/helper.ts index b368912..294fcdd 100644 --- a/web/src/containers/Studio/internal/helper.ts +++ b/web/src/containers/Studio/internal/helper.ts @@ -1,3 +1,5 @@ +import { RunTimeType } from '../../../context/appContext' + export const getLanguageFromExtension = (extension: string) => { if (extension === 'js') return 'javascript' @@ -12,3 +14,26 @@ export const getSelection = (editor: any) => { const selection = editor?.getModel().getValueInRange(editor?.getSelection()) return selection ?? '' } + +export const programPathInjection = ( + code: string, + path: string, + runtime: RunTimeType +) => { + if (path) { + if (runtime === RunTimeType.JS) { + return `const _PROGRAM = '${path}';\n${code}` + } + if (runtime === RunTimeType.PY) { + return `_PROGRAM = '${path}';\n${code}` + } + if (runtime === RunTimeType.R) { + return `._PROGRAM = '${path}';\n${code}` + } + if (runtime === RunTimeType.SAS) { + return `%let _program = '${path}';\n${code}` + } + } + + return code +} diff --git a/web/src/containers/Studio/internal/hooks/useEditor.ts b/web/src/containers/Studio/internal/hooks/useEditor.ts index 7cb8dd3..4a12bdb 100644 --- a/web/src/containers/Studio/internal/hooks/useEditor.ts +++ b/web/src/containers/Studio/internal/hooks/useEditor.ts @@ -10,7 +10,7 @@ import { } from 'react' import { DiffEditorDidMount, EditorDidMount, monaco } from 'react-monaco-editor' import { SelectChangeEvent } from '@mui/material' -import { getSelection } from '../helper' +import { getSelection, programPathInjection } from '../helper' import { AppContext, RunTimeType } from '../../../../context/appContext' import { AlertSeverityType } from '../../../../components/snackbar' import { @@ -151,7 +151,14 @@ const useEditor = ({ const runCode = (code: string) => { setIsLoading(true) axios - .post(`/SASjsApi/code/execute`, { code, runTime: selectedRunTime }) + .post(`/SASjsApi/code/execute`, { + code: programPathInjection( + code, + selectedFilePath, + selectedRunTime as RunTimeType + ), + runTime: selectedRunTime + }) .then((res: any) => { setWebout(res.data.split(SASJS_LOGS_SEPARATOR)[0] ?? '') setLog(res.data.split(SASJS_LOGS_SEPARATOR)[1] ?? '')