Completely change naming conventions of field forms and definition macros. Close #32
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
/**
|
||||
* Helper functions
|
||||
*/
|
||||
(defun selectedText []
|
||||
(function selectedText []
|
||||
(if (and activeTextEditor .selection activeTextEditor)
|
||||
(let [document
|
||||
// TODO should be able to use activeTextEditor.document and have the alias still work
|
||||
@@ -35,12 +35,12 @@
|
||||
|
||||
// TODO make an async annotation that throws an error if the promise is not wrapped in awaitLet or awaitBegin or returned by an async function?
|
||||
// but in some cases it doesn't matter and there are so many edge cases.
|
||||
(defun insertAt [:vscode.Position pos text]
|
||||
(function insertAt [:vscode.Position pos text]
|
||||
(.edit activeTextEditor
|
||||
(lambda [e]
|
||||
(e.insert pos text))))
|
||||
|
||||
(defun insert [text]
|
||||
(function insert [text]
|
||||
// TODO this let is because identifier alias dot access is broken:
|
||||
(let [editor activeTextEditor]
|
||||
(insertAt editor.selection.active text)))
|
||||
@@ -49,18 +49,18 @@
|
||||
* State
|
||||
*/
|
||||
|
||||
(defvar :Map<String,Command> commands (new Map))
|
||||
(defvar :Map<String,ShortcutKey> commandShortcuts (new Map))
|
||||
(var :Map<String,Command> commands (new Map))
|
||||
(var :Map<String,ShortcutKey> commandShortcuts (new Map))
|
||||
|
||||
(defvar &mut :String lastCommand null)
|
||||
(defvar parser (new Parser))
|
||||
(defvar interp (new Interp))
|
||||
(var &mut :String lastCommand null)
|
||||
(var parser (new Parser))
|
||||
(var interp (new Interp))
|
||||
|
||||
/**
|
||||
* Functionality
|
||||
*/
|
||||
|
||||
(defun :Dynamic evalString [:String kissStr]
|
||||
(function :Dynamic evalString [:String kissStr]
|
||||
(try
|
||||
(interp.execute
|
||||
(parser.parseString
|
||||
@@ -69,16 +69,16 @@
|
||||
(errorMessage "Error `${e}` from $kissStr")
|
||||
null)))
|
||||
|
||||
(defun :Void evalAndPrint [&opt :String selectedText]
|
||||
(function :Void evalAndPrint [&opt :String selectedText]
|
||||
(if selectedText
|
||||
(infoMessage (Std.string (evalString selectedText))))
|
||||
|
||||
(awaitLet [kissStr (inputBox)]
|
||||
(infoMessage (Std.string (evalString kissStr)))))
|
||||
|
||||
(defun :Void runCommand [&opt command] (_runCommand command))
|
||||
(function :Void runCommand [&opt command] (_runCommand command))
|
||||
|
||||
(defun :Void _runCommand [&opt command inputText]
|
||||
(function :Void _runCommand [&opt command inputText]
|
||||
(unless inputText (set inputText (selectedText)))
|
||||
(if command
|
||||
{(set lastCommand command) ((dictGet commands command) inputText)}
|
||||
@@ -95,13 +95,13 @@
|
||||
(set lastCommand chosenCommand.label)
|
||||
((dictGet commands chosenCommand.label) inputText))))))
|
||||
|
||||
(defun :Void runLastCommand [&opt _]
|
||||
(function :Void runLastCommand [&opt _]
|
||||
(if lastCommand
|
||||
(runCommand lastCommand)
|
||||
(errorMessage "No Kiss command was run previously.")))
|
||||
|
||||
(defvar &mut :vscode.WebviewPanel shortcutPanel null)
|
||||
(defun :Void showShortcutPanel [&opt :Map<String,ShortcutKey> prefixMap]
|
||||
(var &mut :vscode.WebviewPanel shortcutPanel null)
|
||||
(function :Void showShortcutPanel [&opt :Map<String,ShortcutKey> prefixMap]
|
||||
// Preserve the selected text and focused document before opening the webview:
|
||||
(let [inputText (selectedText)]
|
||||
// When called without a prefixMap, if a shortcut panel is still open, close it and start over:
|
||||
@@ -133,7 +133,7 @@
|
||||
{(warningMessage "$key is not mapped to a shortcut in this context")(return)}))))
|
||||
(set shortcutPanel.webview.html (shortcutPanelHtml prefixMap))))
|
||||
|
||||
(defun shortcutPanelHtml [:Map<String,ShortcutKey> prefixMap]
|
||||
(function shortcutPanelHtml [:Map<String,ShortcutKey> prefixMap]
|
||||
(let [shortcutParagraphs
|
||||
(for =>key shortcutKey prefixMap
|
||||
"<p><strong>${key}</strong> - $(case shortcutKey
|
||||
@@ -159,11 +159,11 @@
|
||||
</body>
|
||||
</html>"))
|
||||
|
||||
(defun :Void runKeyboardShortcut [&opt _]
|
||||
(function :Void runKeyboardShortcut [&opt _]
|
||||
(showShortcutPanel))
|
||||
|
||||
// Extract [k]eyboard [s]hortcuts from a string:
|
||||
(defun extractKeyboardShortcuts [str &opt :Stream stream :String shortcuts]
|
||||
(function extractKeyboardShortcuts [str &opt :Stream stream :String shortcuts]
|
||||
(unless stream (set stream (Stream.fromString str)))
|
||||
(unless shortcuts (set shortcuts ""))
|
||||
(case (stream.takeUntilAndDrop "[")
|
||||
@@ -177,7 +177,7 @@
|
||||
(None
|
||||
shortcuts)))
|
||||
|
||||
(defun :Void registerShortcut [keys description &opt :Map<String,ShortcutKey> prefixMap]
|
||||
(function :Void registerShortcut [keys description &opt :Map<String,ShortcutKey> prefixMap]
|
||||
(unless prefixMap (set prefixMap commandShortcuts))
|
||||
(let [firstKey (keys.shift)]
|
||||
(cond
|
||||
@@ -199,16 +199,16 @@
|
||||
(registerShortcut keys description innerPrefixMap))
|
||||
(dictSet prefixMap firstKey (Final description)))))))
|
||||
|
||||
(defun registerCommand [description command]
|
||||
(function registerCommand [description command]
|
||||
(dictSet commands description command)
|
||||
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
|
||||
(registerShortcut (keyboardShortcut.split "") description)))
|
||||
|
||||
// Register a VSCode command (built-in, or from an extension)
|
||||
(defun registerExistingCommand [description command]
|
||||
(function registerExistingCommand [description command]
|
||||
(registerCommand description (lambda :Void [&opt _] (executeCommand command))))
|
||||
|
||||
(defun :Void registerBuiltins []
|
||||
(function :Void registerBuiltins []
|
||||
(set Prelude.print
|
||||
->[v] {
|
||||
(infoMessage (Std.string v))
|
||||
@@ -220,7 +220,7 @@
|
||||
(registerCommand "[n]ew kiss class" newKissClass))
|
||||
|
||||
// TODO standardize this with KissInterp
|
||||
(defun :Void prepareInterp []
|
||||
(function :Void prepareInterp []
|
||||
(interp.variables.set "kiss"
|
||||
(object
|
||||
Prelude
|
||||
@@ -244,7 +244,7 @@
|
||||
(awaitLet [,v (inputBox)]
|
||||
,@body)))
|
||||
|
||||
(defun :Void newKissClass [&opt _]
|
||||
(function :Void newKissClass [&opt _]
|
||||
(awaitLet [className (inputBox)]
|
||||
(let [currentFile
|
||||
.fileName .document activeTextEditor
|
||||
@@ -275,4 +275,4 @@ import kiss.List;
|
||||
class ${className} {}
|
||||
")
|
||||
(File.saveContent kissFile "")
|
||||
(Vscode.window.showTextDocument (Uri.file kissFile)))))
|
||||
(Vscode.window.showTextDocument (Uri.file kissFile)))))
|
||||
|
@@ -1,2 +1,2 @@
|
||||
(defun init []
|
||||
(return))
|
||||
(function init []
|
||||
(return))
|
||||
|
@@ -1,6 +1,6 @@
|
||||
(defun :Void init []
|
||||
(function :Void init []
|
||||
(registerCommand "print a nice message"
|
||||
(lambda :Void [&opt selectedText]
|
||||
(infoMessage "Hello world!")
|
||||
(when selectedText
|
||||
(infoMessage (+ "Also, " selectedText))))))
|
||||
(infoMessage (+ "Also, " selectedText))))))
|
||||
|
@@ -1,15 +1,15 @@
|
||||
(defun userHome [] (or (Sys.getEnv "MSYSHOME") (Sys.getEnv "HOME") (Sys.getEnv "UserProfile")))
|
||||
(defun userConfigDir []
|
||||
(function userHome [] (or (Sys.getEnv "MSYSHOME") (Sys.getEnv "HOME") (Sys.getEnv "UserProfile")))
|
||||
(function userConfigDir []
|
||||
(joinPath
|
||||
(userHome)
|
||||
".kiss"))
|
||||
|
||||
(defvar &mut activeConfigDir "")
|
||||
(defvar &mut lastConfigDir "")
|
||||
(defvar &mut builtinConfigDir "")
|
||||
(defvar &mut :KissConfig config null)
|
||||
(var &mut activeConfigDir "")
|
||||
(var &mut lastConfigDir "")
|
||||
(var &mut builtinConfigDir "")
|
||||
(var &mut :KissConfig config null)
|
||||
|
||||
(defun walkDirectory [basePath directory :String->Void processFile :String->Void processSubdirectory]
|
||||
(function walkDirectory [basePath directory :String->Void processFile :String->Void processSubdirectory]
|
||||
(doFor fileOrFolder (FileSystem.readDirectory (joinPath basePath directory))
|
||||
(case fileOrFolder
|
||||
((when (FileSystem.isDirectory (joinPath basePath directory folder)) folder)
|
||||
@@ -19,7 +19,7 @@
|
||||
(file
|
||||
(processFile (joinPath directory file))))))
|
||||
|
||||
(defun :Void tryLoadConfig [&opt :String text]
|
||||
(function :Void tryLoadConfig [&opt :String text]
|
||||
// TODO if a config object is active and a shortcut panel is open, dispose the panel before we lose the handle in the current config object
|
||||
|
||||
// If a backup exists, delete it
|
||||
@@ -97,7 +97,7 @@
|
||||
(Vscode.window.showErrorMessage errorMessage))))))))
|
||||
|
||||
(#unless test
|
||||
(defun _activate [:ExtensionContext context]
|
||||
(function _activate [:ExtensionContext context]
|
||||
(context.subscriptions.push
|
||||
(Vscode.commands.registerCommand
|
||||
"kiss.reloadConfig"
|
||||
@@ -134,7 +134,7 @@
|
||||
(set lastConfigDir (joinPath (userHome) ".kiss-vscode" "lastActiveConfig"))
|
||||
(tryLoadConfig)))
|
||||
|
||||
(defun :Void main []
|
||||
(function :Void main []
|
||||
(#when test
|
||||
(set builtinConfigDir "config")
|
||||
(set activeConfigDir "_activeConfig")
|
||||
@@ -142,4 +142,4 @@
|
||||
(tryLoadConfig)
|
||||
// Load the config twice more to make sure it moves the last active config out of the way properly:
|
||||
(tryLoadConfig)
|
||||
(tryLoadConfig)))
|
||||
(tryLoadConfig)))
|
||||
|
@@ -47,7 +47,7 @@
|
||||
</dict>
|
||||
</dict>
|
||||
<key>match</key>
|
||||
<string>(?:\()((?i:defmacro|defun|classFunction|classMethod|def[A-Z]\S+))\s+((?:\w|[+\-<>/*&=.?!$%:@\[\]^{}~#|])+)</string>
|
||||
<string>(?:\()((?i:defmacro|defMacro|defun|function|defmethod|method|def[A-Z]\S+))\s+((?:\w|[+\-<>/*&=.?!$%:@\[\]^{}~#|])+)</string>
|
||||
<key>name</key>
|
||||
<string>meta.function.kiss</string>
|
||||
</dict>
|
||||
@@ -57,23 +57,6 @@
|
||||
<key>name</key>
|
||||
<string>meta.function-parameters.kiss</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>captures</key>
|
||||
<dict>
|
||||
<key>1</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>storage.type.function-type.kiss</string>
|
||||
</dict>
|
||||
<key>2</key>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>entity.name.type.kiss</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>match</key>
|
||||
<string>(?:\()((?i:deftype|defstruct))\s+((?:\w|[+\-<>/*&=.?!$%:@\[\]^{}~#|])+)</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>captures</key>
|
||||
<dict>
|
||||
@@ -89,7 +72,7 @@
|
||||
</dict>
|
||||
</dict>
|
||||
<key>match</key>
|
||||
<string>(?:\()((?i:defvar|defprop|classVar|classProp))\s+((?:\w|[+\-<>/*&=.?!$%:@\[\]^{}~#|])+)</string>
|
||||
<string>(?:\()((?i:defvar|defprop|var|prop))\s+((?:\w|[+\-<>/*&=.?!$%:@\[\]^{}~#|])+)</string>
|
||||
</dict>
|
||||
<!-- <dict>
|
||||
<key>captures</key>
|
||||
@@ -133,7 +116,7 @@
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<!-- TODO cut this down and add some missing ones -->
|
||||
<string>(?<=\()(?i:\*|\*\*|\*\*\*|\+|\+\+|\+\+\+|\-|/|//|///|/=|<|<=|=|>|>=|and|apply|assert|begin|break|case|catch|concat|cond|continue|count|defMacro|defReaderMacro|defun|classMethod|classFunction|defvar|classVar|classProp|for|doFor|eighth|eval|fifth|first|fourth|localFunction|localVar|symbol|if|load|withFunction|withFunctions|lambda|last|let|loop|map|max|min|ninth|not|nth|setNth|getDict|setDict|or|otherwise|print|rest|return|reversed|second|set|sixth|Some|sort|symbolName|symbolNameValue|tenth|the|third|throw|trace|when|unless|ifLet|whenLet|unlessLet|forCase|doForCase|with[A-Z]\S+)(?=\s+)</string>
|
||||
<string>(?<=\()(?i:\*|\*\*|\*\*\*|\+|\+\+|\+\+\+|\-|/|//|///|/=|<|<=|=|>|>=|and|apply|assert|begin|break|case|catch|concat|cond|continue|count|defMacro|defReaderMacro|defun|defmethod|method|function|defvar|var|defprop|prop|for|doFor|eighth|eval|fifth|first|fourth|localFunction|localVar|symbol|if|load|withFunction|withFunctions|lambda|last|let|loop|map|max|min|ninth|not|nth|setNth|getDict|setDict|or|otherwise|print|rest|return|reversed|second|set|sixth|Some|sort|symbolName|symbolNameValue|tenth|the|third|throw|trace|when|unless|ifLet|whenLet|unlessLet|forCase|doForCase|with[A-Z]\S+)(?=\s+)</string>
|
||||
<key>name</key>
|
||||
<string>keyword.control.kiss</string>
|
||||
</dict>
|
||||
|
Reference in New Issue
Block a user