This is an automated email from the ASF dual-hosted git repository.
shanedell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git
The following commit(s) were added to refs/heads/main by this push:
new 439d4d5 Respect dataEditor global settings in settings.json, then the
local ones in launch.json
439d4d5 is described below
commit 439d4d5dc70ededcf661dedfa09f0fa20405f486
Author: Jeremy Yao <[email protected]>
AuthorDate: Wed Feb 26 16:55:55 2025 -0500
Respect dataEditor global settings in settings.json, then the local ones in
launch.json
Resolves #1127
---
src/dataEditor/config/Extract.ts | 27 ++++++++++++++++---
src/utils.ts | 56 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 3 deletions(-)
diff --git a/src/dataEditor/config/Extract.ts b/src/dataEditor/config/Extract.ts
index e8972a7..3cf6d67 100644
--- a/src/dataEditor/config/Extract.ts
+++ b/src/dataEditor/config/Extract.ts
@@ -18,6 +18,8 @@ import { Uri, workspace } from 'vscode'
import { Config, ConfigJSON, IConfig } from './Config'
import XDGAppPaths from 'xdg-app-paths'
import path from 'path'
+import { substituteVSCodeEnvVariables } from '../../utils'
+import { ServerPortKeyword } from './ConfigKeyword'
export const APP_DATA_PATH: string = XDGAppPaths({ name: 'omega_edit' }).data()
export function addToAppDataPath(filename: string): string {
@@ -41,12 +43,31 @@ function extractDataEditorConfigFromQuery(
export function extractConfigurationVariables(): IConfig {
const configObjArray = queryConfigurationsArray()
+ const workspaceConfig = workspace.getConfiguration()
+ const port = workspaceConfig.dataEditor?.port || Config.Default.port
+
+ const noLaunchJSONConfig: Config = {
+ ...Config.Default, // Populate settings w/ default configs
+ // override defaults if they exist in global user's settings.json below
+ port: port, // Get dataEdtior port from settings.json if it exists
+ logLevel:
+ workspaceConfig.dataEditor?.logging?.level || Config.Default.logLevel,
// Get logging level from settings.json if exists
+ logFile: workspaceConfig.dataEditor?.logging?.file
+ ? path.normalize(
+ substituteVSCodeEnvVariables(
+ workspaceConfig.dataEditor?.logging?.file,
+ APP_DATA_PATH
+ ).replaceAll(ServerPortKeyword, port)
+ )
+ : Config.Default.logFile, // Get logging file path from settings.json if
exists
+ }
+
if (configObjArray === undefined || configObjArray.length === 0)
- return Config.Default
+ return noLaunchJSONConfig // No launch specified for DFDL
return configObjArray[0]['dataEditor'] === undefined
- ? Config.Default
- : Config.fromConfigJSON(extractDataEditorConfigFromQuery(configObjArray))
+ ? noLaunchJSONConfig // There is a launch option specified for
daffodil-vscode, but somehow missing "dataEditor" part
+ : Config.fromConfigJSON(extractDataEditorConfigFromQuery(configObjArray))
// Use dataEditor section in launch.json
}
export default { addToAppDataPath, rootPath, extractConfigurationVariables }
diff --git a/src/utils.ts b/src/utils.ts
index 0d459f2..bfb6c19 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -353,3 +353,59 @@ export function ensureFile(path: string): string {
}
return path
}
+
+/**
+ * Substitutes in VSCode and environmental variables into a given string.
+ *
+ * @param input - given string
+ * @param alternativeWorkspace - alternative workspace location if vscode
can't find a good workspace
+ * @returns modified input, but with all ${} corresponding to VSCode or Env
variables substituted with their
+ */
+export function substituteVSCodeEnvVariables(
+ input: string,
+ alternativeWorkspace?: string
+): string {
+ const workspaceFolder =
+ vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ||
+ alternativeWorkspace ||
+ ''
+ const homeDir = os.homedir()
+
+ // Common VS Code variables
+ const variableMap: Record<string, string> = {
+ '${workspaceFolder}': workspaceFolder,
+ '${workspaceRoot}': workspaceFolder,
+ '${userHome}': homeDir,
+ '${file}': vscode.window.activeTextEditor?.document.uri.fsPath || '',
+ '${relativeFile}': path.relative(
+ workspaceFolder,
+ vscode.window.activeTextEditor?.document.uri.fsPath || ''
+ ),
+ '${fileBasename}': path.basename(
+ vscode.window.activeTextEditor?.document.uri.fsPath || ''
+ ),
+ '${fileDirname}': path.dirname(
+ vscode.window.activeTextEditor?.document.uri.fsPath || ''
+ ),
+ '${fileExtname}': path.extname(
+ vscode.window.activeTextEditor?.document.uri.fsPath || ''
+ ),
+ '${fileBasenameNoExtension}': path.basename(
+ vscode.window.activeTextEditor?.document.uri.fsPath || '',
+ path.extname(vscode.window.activeTextEditor?.document.uri.fsPath || '')
+ ),
+ '${cwd}': process.cwd(),
+ }
+
+ // Add all environment variables dynamically
+ Object.entries(process.env).forEach(([key, value]) => {
+ if (value) {
+ variableMap[`$\{env:${key}\}`] = value
+ }
+ })
+
+ // Substitute all variables in the input string
+ return Object.entries(variableMap).reduce((result, [variable, value]) => {
+ return result.replaceAll(variable, value)
+ }, input)
+}