This repository has been archived by the owner on Jul 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 40b5cab
Showing
16 changed files
with
1,814 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
node_modules | ||
.vscode-test/ | ||
*.vsix | ||
.shadow-cljs/ | ||
.nrepl-port | ||
pom.xml | ||
*.idea/ | ||
*.DS_Store | ||
out/ | ||
lib/ | ||
test-out/ | ||
.vscode/settings.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "calva-lib", | ||
"displayName": "The Calva Library", | ||
"description": "A common library for the Calva Family of extensions", | ||
"version": "0.0.1", | ||
"keywords": [ | ||
"Clojure", | ||
"ClojureScript", | ||
"EDN", | ||
"Formatting", | ||
"Pretty" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BetterThanTomorrow/calva-lib.git" | ||
}, | ||
"scripts": { | ||
"watch": "npx shadow-cljs watch :test :calva-lib", | ||
"release": "npx shadow-cljs release :calva-lib", | ||
"compile": "npx shadow-cljs compile :calva-lib", | ||
"test": "node ./node_modules/vscode/bin/test" | ||
}, | ||
"devDependencies": { | ||
"shadow-cljs": "^2.7.6" | ||
}, | ||
"dependencies": { | ||
"paredit.js": "^0.3.4", | ||
"parinfer": "^3.12.0" | ||
}, | ||
"license": "MIT" | ||
} |
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,2 @@ | ||
*.js | ||
*.js.map |
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,17 @@ | ||
{ | ||
"name": "@pez/calva-lib", | ||
"version": "0.0.1", | ||
"description": "The Calva Common Library", | ||
"main": "calva.fmt.formatter.js", | ||
"keywords": [ | ||
"clojurescript", | ||
"cljs", | ||
"shadow-cljs" | ||
], | ||
"author": "Peter Strömberg", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BetterThanTomorrow/calva-lib.git" | ||
} | ||
} |
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,21 @@ | ||
{:dependencies [[pez/cljfmt "0.6.2-ALIGN"] | ||
#_[zprint "0.4.11"] | ||
[cider/cider-nrepl "0.19.0-SNAPSHOT"]] | ||
|
||
:source-paths ["src" "test"] | ||
|
||
:builds {:calva-lib | ||
{:target :npm-module | ||
:runtime :node | ||
:entries [calva.fmt.formatter | ||
calva.fmt.inferer | ||
calva.js-utils | ||
calva.main] | ||
:output-dir "packages/calva_lib" | ||
:devtools {:before-load-async calva.main/stop | ||
:after-load calva.main/start}} | ||
:test | ||
{:target :node-test | ||
:output-to "test-out/tests.js" | ||
:ns-regexp "-test$" | ||
:autorun true}}} |
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,37 @@ | ||
(ns calva.fmt.editor | ||
(:require [calva.fmt.util :as util])) | ||
|
||
|
||
(defn raplacement-edits-for-diffing-lines | ||
"Returns a list of replacement edits to apply to `old-text` to get `new-text`. | ||
Edits will be in the form `[:replace [range] text]`, | ||
where `range` is in the form `[[start-line start-char] [end-line end-char]]`. | ||
NB: The two versions need to have the same amount of lines." | ||
[old-text new-text] | ||
(let [old-lines (util/split-into-lines old-text) | ||
new-lines (util/split-into-lines new-text)] | ||
(->> (map vector (range) old-lines new-lines) | ||
(remove (fn [[line o n]] (= o n))) | ||
(mapv (fn [[line o n]] | ||
{:edit "replace" | ||
:start {:line line | ||
:character 0} | ||
:end {:line line | ||
:character (count o)} | ||
:text n}))))) | ||
|
||
|
||
(comment | ||
(raplacement-edits-for-diffing-lines "foo\nfooo\nbar\nbar" | ||
"foo\nbar\nbaz\nbar") | ||
(->> (map vector | ||
[:foo :foo :foo] | ||
[:foo :bar :foo] | ||
(range)) | ||
(remove (fn [[o n i]] | ||
(= o n)))) | ||
(filter some? | ||
(map (fn [o n line] (when-not (= o n) [o n line])) | ||
[:foo :foo :foo] | ||
[:foo :bar :foo] | ||
(range)))) |
Oops, something went wrong.