-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1053 from BetterThanTomorrow/use_cljs_for_state
Use cljs for state
- Loading branch information
Showing
36 changed files
with
18,364 additions
and
1,314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(ns calva.state) | ||
|
||
(defonce ^:private state (atom {})) | ||
|
||
(defn set-state-value! [key value] | ||
(swap! state assoc key value)) | ||
|
||
(defn remove-state-value! [key] | ||
(swap! state dissoc key)) | ||
|
||
(defn get-state-value [key] | ||
(get @state key)) | ||
|
||
(defn get-state [] | ||
@state) | ||
|
||
(comment | ||
(set-state-value! "hello" "world") | ||
(get-state) | ||
(remove-state-value! "hello")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(ns calva.state-test | ||
(:require [cljs.test :refer [testing deftest is use-fixtures]] | ||
[calva.state :as state])) | ||
|
||
(use-fixtures :each | ||
{:before (fn [] (reset! state/state {}))}) | ||
|
||
(deftest set-state-value!-test | ||
(testing "Should write value to state, given key" | ||
(state/set-state-value! "hello" "world") | ||
(is (= {"hello" "world"} @state/state)))) | ||
|
||
(deftest remove-state-value!-test | ||
(testing "Should remove value from state, given key" | ||
(reset! state/state {"hello" "world"}) | ||
(state/remove-state-value! "hello") | ||
(is (= {} @state/state)))) | ||
|
||
(deftest get-state-value-test | ||
(testing "Should get value from state, given key" | ||
(reset! state/state {"hello" "world"}) | ||
(is (= "world" (state/get-state-value "hello"))))) | ||
|
||
(deftest get-state-test | ||
(testing "Should return all state" | ||
(let [all-state {"hello" "world" "fizz" "buzz"}] | ||
(reset! state/state all-state) | ||
(is (= all-state (state/get-state)))))) | ||
|
||
(comment | ||
(state/get-state)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,68 @@ | ||
const config = { | ||
REPL_FILE_EXT: 'calva-repl', | ||
KEYBINDINGS_ENABLED_CONFIG_KEY: 'calva.keybindingsEnabled', | ||
KEYBINDINGS_ENABLED_CONTEXT_KEY: 'calva:keybindingsEnabled' | ||
}; | ||
import * as vscode from 'vscode'; | ||
import { customREPLCommandSnippet } from './evaluate'; | ||
import { ReplConnectSequence } from './nrepl/connectSequence'; | ||
import { PrettyPrintingOptions } from './printer'; | ||
|
||
const REPL_FILE_EXT = 'calva-repl'; | ||
const KEYBINDINGS_ENABLED_CONFIG_KEY = 'calva.keybindingsEnabled'; | ||
const KEYBINDINGS_ENABLED_CONTEXT_KEY = 'calva:keybindingsEnabled'; | ||
|
||
type ReplSessionType = 'clj' | 'cljs'; | ||
|
||
export { | ||
ReplSessionType | ||
// include the 'file' and 'untitled' to the | ||
// document selector. All other schemes are | ||
// not known and therefore not supported. | ||
const documentSelector = [ | ||
{ scheme: 'file', language: 'clojure' }, | ||
{ scheme: 'jar', language: 'clojure' }, | ||
{ scheme: 'untitled', language: 'clojure' } | ||
]; | ||
|
||
/** | ||
* Trims EDN alias and profile names from any surrounding whitespace or `:` characters. | ||
* This in order to free the user from having to figure out how the name should be entered. | ||
* @param {string} name | ||
* @return {string} The trimmed name | ||
*/ | ||
function _trimAliasName(name: string): string { | ||
return name.replace(/^[\s,:]*/, "").replace(/[\s,:]*$/, "") | ||
} | ||
|
||
export default config; | ||
// TODO find a way to validate the configs | ||
function getConfig() { | ||
const configOptions = vscode.workspace.getConfiguration('calva'); | ||
return { | ||
format: configOptions.get("formatOnSave"), | ||
evaluate: configOptions.get("evalOnSave"), | ||
test: configOptions.get("testOnSave"), | ||
showDocstringInParameterHelp: configOptions.get("showDocstringInParameterHelp") as boolean, | ||
jackInEnv: configOptions.get("jackInEnv"), | ||
jackInDependencyVersions: configOptions.get("jackInDependencyVersions") as { JackInDependency: string }, | ||
openBrowserWhenFigwheelStarted: configOptions.get("openBrowserWhenFigwheelStarted") as boolean, | ||
customCljsRepl: configOptions.get("customCljsRepl", null), | ||
replConnectSequences: configOptions.get("replConnectSequences") as ReplConnectSequence[], | ||
myLeinProfiles: configOptions.get("myLeinProfiles", []).map(_trimAliasName) as string[], | ||
myCljAliases: configOptions.get("myCljAliases", []).map(_trimAliasName) as string[], | ||
asyncOutputDestination: configOptions.get("sendAsyncOutputTo") as string, | ||
customREPLCommandSnippets: configOptions.get("customREPLCommandSnippets", []), | ||
customREPLCommandSnippetsGlobal: configOptions.inspect("customREPLCommandSnippets").globalValue as customREPLCommandSnippet[], | ||
customREPLCommandSnippetsWorkspace: configOptions.inspect("customREPLCommandSnippets").workspaceValue as customREPLCommandSnippet[], | ||
customREPLCommandSnippetsWorkspaceFolder: configOptions.inspect("customREPLCommandSnippets").workspaceFolderValue as customREPLCommandSnippet[], | ||
prettyPrintingOptions: configOptions.get("prettyPrintingOptions") as PrettyPrintingOptions, | ||
enableJSCompletions: configOptions.get("enableJSCompletions") as boolean, | ||
autoOpenREPLWindow: configOptions.get("autoOpenREPLWindow") as boolean, | ||
autoOpenJackInTerminal: configOptions.get("autoOpenJackInTerminal") as boolean, | ||
referencesCodeLensEnabled: configOptions.get('referencesCodeLens.enabled') as boolean, | ||
displayDiagnostics: configOptions.get('displayDiagnostics') as boolean, | ||
hideReplUi: configOptions.get('hideReplUi') as boolean | ||
}; | ||
} | ||
|
||
export { | ||
REPL_FILE_EXT, | ||
KEYBINDINGS_ENABLED_CONFIG_KEY, | ||
KEYBINDINGS_ENABLED_CONTEXT_KEY, | ||
documentSelector, | ||
ReplSessionType, | ||
getConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.