Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Commit

Permalink
Calva-lib -> git
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Dec 6, 2018
0 parents commit 40b5cab
Show file tree
Hide file tree
Showing 16 changed files with 1,814 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
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
828 changes: 828 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions package.json
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"
}
2 changes: 2 additions & 0 deletions packages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js
*.js.map
17 changes: 17 additions & 0 deletions packages/package.json
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"
}
}
21 changes: 21 additions & 0 deletions shadow-cljs.edn
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}}}
37 changes: 37 additions & 0 deletions src/calva/fmt/editor.cljs
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))))
Loading

0 comments on commit 40b5cab

Please sign in to comment.