From 978ffb8b53966352cef419ff4cdbdfcda0db6c2f Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 12 Nov 2024 15:47:29 -0600 Subject: [PATCH] corresponding file support for C/C++ --- package.json | 18 +++++++++--------- src/Main.kiss | 1 + src/commands/CodeTools.kiss | 24 ++++++++++++++++++++++++ src/commands/KissTools.kiss | 17 +---------------- 4 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 src/commands/CodeTools.kiss diff --git a/package.json b/package.json index 7cbbba3c..4baccde4 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,11 @@ "mac": "Cmd+; Cmd+u", "key": "Ctrl+; Ctrl+u" }, + { + "command": "kiss-vscode.showCorrespondingFile", + "mac": "Cmd+; Cmd+f", + "key": "Ctrl+; Ctrl+f" + }, { "command": "kiss-vscode.evalAndPrint", "mac": "Cmd+; Cmd+e", @@ -49,11 +54,6 @@ "mac": "Cmd+; Cmd+n", "key": "Ctrl+; Ctrl+n" }, - { - "command": "kiss-vscode.showCorrespondingFile", - "mac": "Cmd+; Cmd+f", - "key": "Ctrl+; Ctrl+f" - }, { "command": "kiss-vscode.insertUTestCase", "mac": "Cmd+; Cmd+c", @@ -79,6 +79,10 @@ "title": "kiss-vscode: Check test.sh, then update and reinstall the kiss-vscode extension you are editing", "command": "kiss-vscode.testAndUpdateExtension" }, + { + "title": "kiss-vscode: Open the corresponding header/source file to this one", + "command": "kiss-vscode.showCorrespondingFile" + }, { "title": "kiss-vscode: Evaluate and print a kiss expression's value", "command": "kiss-vscode.evalAndPrint" @@ -87,10 +91,6 @@ "title": "kiss-vscode: Create a new kiss class", "command": "kiss-vscode.newKissClass" }, - { - "title": "kiss-vscode: Open the corresponding .kiss/.hx file to this one", - "command": "kiss-vscode.showCorrespondingFile" - }, { "title": "kiss-vscode: Generate a UTest test case in this .hx/.kiss file", "command": "kiss-vscode.insertUTestCase" diff --git a/src/Main.kiss b/src/Main.kiss index 21370584..ced9483c 100644 --- a/src/Main.kiss +++ b/src/Main.kiss @@ -7,5 +7,6 @@ (awaitLetCatchThroughErrorMessage) (allowRuntimeConversion) (load "commands/ExtensionTools.kiss") + (load "commands/CodeTools.kiss") (load "commands/KissTools.kiss") (load "commands/Lines.kiss")) \ No newline at end of file diff --git a/src/commands/CodeTools.kiss b/src/commands/CodeTools.kiss new file mode 100644 index 00000000..d5fb56b1 --- /dev/null +++ b/src/commands/CodeTools.kiss @@ -0,0 +1,24 @@ +(function correspondingFileUri [:String sourceOrHeaderFile] + (let [base + (sourceOrHeaderFile.withoutExtension) + ext + (sourceOrHeaderFile.extension) + correspondingExts + (case ext + // Kiss + ("hx" ["kiss" "hollywoo"]) + ("kiss" ["hx"]) + ("hollywoo" ["hx"]) + // C/C++ + ("h" ["c" "cpp"]) + ("hpp" ["cpp"]) + ("cpp" ["h" "hpp"]) + (otherwise (throw "No corresponding extensions for .$ext")))] + (doFor ext correspondingExts + (let [uri (Uri.file "${base}.${ext}")] + (when (sys.FileSystem.exists uri.fsPath) + (return uri)))) + (throw "No corresponding file for $sourceOrHeaderFile"))) + +(defCommand context showCorrespondingFile "Open the corresponding header/source file to this one" "C-; C-f" [] + (showTextDocument (correspondingFileUri .fileName .document activeTextEditor))) diff --git a/src/commands/KissTools.kiss b/src/commands/KissTools.kiss index 7da6a5dd..0c790d9e 100644 --- a/src/commands/KissTools.kiss +++ b/src/commands/KissTools.kiss @@ -40,21 +40,6 @@ class ${className} {} (awaitLet [_ (showTextDocument (Uri.file kissFile) (object viewColumn ViewColumn.Beside))] (executeCommand "workbench.action.keepEditor"))))))) -(function correspondingFile [:String kissOrHxFile] - (let [base - (kissOrHxFile.withoutExtension) - ext - (kissOrHxFile.extension) - correspondingExt - (case ext - ("hx" "kiss") - ("kiss" "hx") - (otherwise (throw "No corresponding file for ${kissOrHxFile}")))] - "${base}.${correspondingExt}")) - -(defCommand context showCorrespondingFile "Open the corresponding .kiss/.hx file to this one" "C-; C-f" [] - (showTextDocument (Uri.file (correspondingFile .fileName .document activeTextEditor)))) - (defCommand context insertUTestCase "Generate a UTest test case in this .hx/.kiss file" "C-; C-c" [] (awaitLet [testName (inputBox) &sync testName @@ -64,7 +49,7 @@ class ${className} {} _test${testName}(); } ") - _ (showTextDocument (Uri.file (correspondingFile .fileName .document activeTextEditor))) + _ (showTextDocument (correspondingFileUri .fileName .document activeTextEditor)) &sync pos (activeTextEditor.document.positionAt .length (activeTextEditor.document.getText)) _ (insertAt pos "