diff --git a/bench.esy.lock/index.json b/bench.esy.lock/index.json index a6b9d1f28e..f1fb63ff7f 100644 --- a/bench.esy.lock/index.json +++ b/bench.esy.lock/index.json @@ -1,5 +1,5 @@ { - "checksum": "e3b06c2adff2f04f842cd48ecae50b0b", + "checksum": "03fcb789f98a1964a223269a253e696f", "root": "Oni2@link-dev:./package.json", "node": { "yarn-pkg-config@github:esy-ocaml/yarn-pkg-config#db3a0b63883606dd57c54a7158d560d6cba8cd79@d41d8cd9": { @@ -803,23 +803,6 @@ "dependencies": [], "devDependencies": [] }, - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9": { - "id": - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9", - "name": "editor-core-types", - "version": "github:onivim/editor-core-types#6a8afaf", - "source": { - "type": "install", - "source": [ "github:onivim/editor-core-types#6a8afaf" ] - }, - "overrides": [], - "dependencies": [ - "refmterr@3.3.2@d41d8cd9", "ocaml@4.10.0@d41d8cd9", - "@opam/ppx_deriving@opam:4.5@d89f2934", - "@opam/dune@opam:2.5.0@e0bac278", "@esy-ocaml/reason@3.6.2@d41d8cd9" - ], - "devDependencies": [ "ocaml@4.10.0@d41d8cd9" ] - }, "debug@3.1.0@d41d8cd9": { "id": "debug@3.1.0@d41d8cd9", "name": "debug", @@ -967,9 +950,7 @@ "esy-sdl2@2.0.10008@d41d8cd9", "esy-oniguruma@github:onivim/esy-oniguruma#4698ce4@d41d8cd9", "esy-macdylibbundler@0.4.5@d41d8cd9", - "esy-angle-prebuilt@1.0.0@d41d8cd9", - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9", - "axios@0.19.2@d41d8cd9", + "esy-angle-prebuilt@1.0.0@d41d8cd9", "axios@0.19.2@d41d8cd9", "@reason-native-web/esy-openssl@1.1.1006@d41d8cd9", "@opam/yojson@github:onivim/yojson:yojson.opam#f480aef@d41d8cd9", "@opam/uutf@opam:1.0.2@4440868f", "@opam/uucp@opam:13.0.0@e9b515e0", diff --git a/esy.lock/index.json b/esy.lock/index.json index 123b0aed98..560155a760 100644 --- a/esy.lock/index.json +++ b/esy.lock/index.json @@ -1,5 +1,5 @@ { - "checksum": "e3b06c2adff2f04f842cd48ecae50b0b", + "checksum": "03fcb789f98a1964a223269a253e696f", "root": "Oni2@link-dev:./package.json", "node": { "yarn-pkg-config@github:esy-ocaml/yarn-pkg-config#db3a0b63883606dd57c54a7158d560d6cba8cd79@d41d8cd9": { @@ -803,23 +803,6 @@ "dependencies": [], "devDependencies": [] }, - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9": { - "id": - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9", - "name": "editor-core-types", - "version": "github:onivim/editor-core-types#6a8afaf", - "source": { - "type": "install", - "source": [ "github:onivim/editor-core-types#6a8afaf" ] - }, - "overrides": [], - "dependencies": [ - "refmterr@3.3.2@d41d8cd9", "ocaml@4.10.0@d41d8cd9", - "@opam/ppx_deriving@opam:4.5@d89f2934", - "@opam/dune@opam:2.5.0@e0bac278", "@esy-ocaml/reason@3.6.2@d41d8cd9" - ], - "devDependencies": [ "ocaml@4.10.0@d41d8cd9" ] - }, "debug@3.1.0@d41d8cd9": { "id": "debug@3.1.0@d41d8cd9", "name": "debug", @@ -966,9 +949,7 @@ "esy-sdl2@2.0.10008@d41d8cd9", "esy-oniguruma@github:onivim/esy-oniguruma#4698ce4@d41d8cd9", "esy-macdylibbundler@0.4.5@d41d8cd9", - "esy-angle-prebuilt@1.0.0@d41d8cd9", - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9", - "axios@0.19.2@d41d8cd9", + "esy-angle-prebuilt@1.0.0@d41d8cd9", "axios@0.19.2@d41d8cd9", "@reason-native-web/esy-openssl@1.1.1006@d41d8cd9", "@opam/yojson@github:onivim/yojson:yojson.opam#f480aef@d41d8cd9", "@opam/uutf@opam:1.0.2@4440868f", "@opam/uucp@opam:13.0.0@e9b515e0", diff --git a/integrationtest.esy.lock/index.json b/integrationtest.esy.lock/index.json index 16215bea76..269f4fba8b 100644 --- a/integrationtest.esy.lock/index.json +++ b/integrationtest.esy.lock/index.json @@ -1,5 +1,5 @@ { - "checksum": "e3b06c2adff2f04f842cd48ecae50b0b", + "checksum": "03fcb789f98a1964a223269a253e696f", "root": "Oni2@link-dev:./package.json", "node": { "yarn-pkg-config@github:esy-ocaml/yarn-pkg-config#db3a0b63883606dd57c54a7158d560d6cba8cd79@d41d8cd9": { @@ -803,23 +803,6 @@ "dependencies": [], "devDependencies": [] }, - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9": { - "id": - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9", - "name": "editor-core-types", - "version": "github:onivim/editor-core-types#6a8afaf", - "source": { - "type": "install", - "source": [ "github:onivim/editor-core-types#6a8afaf" ] - }, - "overrides": [], - "dependencies": [ - "refmterr@3.3.2@d41d8cd9", "ocaml@4.10.0@d41d8cd9", - "@opam/ppx_deriving@opam:4.5@d89f2934", - "@opam/dune@opam:2.5.0@e0bac278", "@esy-ocaml/reason@3.6.2@d41d8cd9" - ], - "devDependencies": [ "ocaml@4.10.0@d41d8cd9" ] - }, "debug@3.1.0@d41d8cd9": { "id": "debug@3.1.0@d41d8cd9", "name": "debug", @@ -966,9 +949,7 @@ "esy-sdl2@2.0.10008@d41d8cd9", "esy-oniguruma@github:onivim/esy-oniguruma#4698ce4@d41d8cd9", "esy-macdylibbundler@0.4.5@d41d8cd9", - "esy-angle-prebuilt@1.0.0@d41d8cd9", - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9", - "axios@0.19.2@d41d8cd9", + "esy-angle-prebuilt@1.0.0@d41d8cd9", "axios@0.19.2@d41d8cd9", "@reason-native-web/esy-openssl@1.1.1006@d41d8cd9", "@opam/yojson@github:onivim/yojson:yojson.opam#f480aef@d41d8cd9", "@opam/uutf@opam:1.0.2@4440868f", "@opam/uucp@opam:13.0.0@e9b515e0", diff --git a/package.json b/package.json index 1232b254db..1022c139ce 100644 --- a/package.json +++ b/package.json @@ -233,7 +233,6 @@ "@opam/yojson": "1.7.0", "@reason-native-web/esy-openssl": "*", "axios": "^0.19.0", - "editor-core-types": "*", "esy-angle-prebuilt": "^1.0.0", "esy-macdylibbundler": "*", "esy-oniguruma": "onivim/esy-oniguruma#4698ce4", @@ -253,11 +252,9 @@ "resolutions": { "@opam/yojson": "onivim/yojson:yojson.opam#f480aef", "revery": "revery-ui/revery#e646df2", - "editor-core-types": "onivim/editor-core-types#6a8afaf", "esy-skia": "revery-ui/esy-skia#a3785f9", "rench": "bryphe/rench#a976fe5", "reasonFuzz": "CrossR/reasonFuzz#1ad6f5d", - "editor-input": "onivim/editor-input#c494950", "isolinear": "revery-ui/isolinear#8cad3b0", "revery-terminal": "revery-ui/revery-terminal#37e19a3", "@opam/fs": "bryphe/reason-native:fs.opam#fd0225c", diff --git a/src/Components/dune b/src/Components/dune index 8e1edab7c1..b42f2aa6bb 100644 --- a/src/Components/dune +++ b/src/Components/dune @@ -18,6 +18,6 @@ Oni2.feature.theme Rench Revery - editor-core-types + Oni2.editor-core-types isolinear )) diff --git a/src/Core/Kernel/dune b/src/Core/Kernel/dune index fe19d1d353..2092c1b4a9 100644 --- a/src/Core/Kernel/dune +++ b/src/Core/Kernel/dune @@ -7,6 +7,6 @@ ppx_deriving_yojson.runtime Revery.zed threads - editor-core-types + Oni2.editor-core-types timber) (preprocess (pps lwt_ppx ppx_deriving_yojson ppx_deriving.show))) diff --git a/src/Core/dune b/src/Core/dune index 24aa631811..d304455432 100644 --- a/src/Core/dune +++ b/src/Core/dune @@ -17,7 +17,7 @@ yojson ppx_deriving.runtime ppx_deriving_yojson.runtime - editor-core-types + Oni2.editor-core-types timber ReasonFuzz decoders-yojson diff --git a/src/Feature/Editor/dune b/src/Feature/Editor/dune index d9d8a5f9a0..c7829785d2 100644 --- a/src/Feature/Editor/dune +++ b/src/Feature/Editor/dune @@ -3,7 +3,7 @@ (public_name Oni2.feature.editor) (inline_tests) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.components Oni2.exthost diff --git a/src/Feature/LanguageSupport/dune b/src/Feature/LanguageSupport/dune index c690e94df3..5dbf8c7ed7 100644 --- a/src/Feature/LanguageSupport/dune +++ b/src/Feature/LanguageSupport/dune @@ -3,7 +3,7 @@ (public_name Oni2.feature.language_support) (inline_tests) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.syntax Oni2.feature.commands diff --git a/src/Feature/Menus/dune b/src/Feature/Menus/dune index fd04c4f127..a64d08fbda 100644 --- a/src/Feature/Menus/dune +++ b/src/Feature/Menus/dune @@ -2,7 +2,7 @@ (name Feature_Menus) (public_name Oni2.feature.menus) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.core.whenExpr Oni2.feature.commands diff --git a/src/Feature/SCM/dune b/src/Feature/SCM/dune index bd0fadac9d..6756b75651 100644 --- a/src/Feature/SCM/dune +++ b/src/Feature/SCM/dune @@ -2,7 +2,7 @@ (name Feature_SCM) (public_name Oni2.feature.scm) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.feature.inputText Oni2.feature.theme diff --git a/src/Feature/Search/dune b/src/Feature/Search/dune index c38e625f99..8e20ca9903 100644 --- a/src/Feature/Search/dune +++ b/src/Feature/Search/dune @@ -2,7 +2,7 @@ (name Feature_Search) (public_name Oni2.feature.search) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.components Oni2.service.font diff --git a/src/Feature/SignatureHelp/dune b/src/Feature/SignatureHelp/dune index 0eca4ba103..9ad8591cc0 100644 --- a/src/Feature/SignatureHelp/dune +++ b/src/Feature/SignatureHelp/dune @@ -2,7 +2,7 @@ (name Feature_SignatureHelp) (public_name Oni2.feature.signature_help) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.syntax Oni2.feature.commands diff --git a/src/Feature/Sneak/dune b/src/Feature/Sneak/dune index e319c2a23a..9be71e3ee3 100644 --- a/src/Feature/Sneak/dune +++ b/src/Feature/Sneak/dune @@ -2,7 +2,7 @@ (name Feature_Sneak) (public_name Oni2.feature.sneak) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.feature.commands Oni2.feature.theme diff --git a/src/Feature/StatusBar/dune b/src/Feature/StatusBar/dune index 7202eb55a3..7a3ac77318 100644 --- a/src/Feature/StatusBar/dune +++ b/src/Feature/StatusBar/dune @@ -2,7 +2,7 @@ (name Feature_StatusBar) (public_name Oni2.feature.statusbar) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.feature.contextMenu Oni2.feature.editor diff --git a/src/Feature/Syntax/dune b/src/Feature/Syntax/dune index 4b579c9667..250fc81555 100644 --- a/src/Feature/Syntax/dune +++ b/src/Feature/Syntax/dune @@ -2,7 +2,7 @@ (name Feature_Syntax) (public_name Oni2.feature.syntax) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.components Oni2.syntax diff --git a/src/Feature/Terminal/dune b/src/Feature/Terminal/dune index 3af961f65b..cc807a0ed1 100644 --- a/src/Feature/Terminal/dune +++ b/src/Feature/Terminal/dune @@ -2,7 +2,7 @@ (name Feature_Terminal) (public_name Oni2.feature.terminal) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.components Oni2.service.terminal diff --git a/src/Feature/TitleBar/dune b/src/Feature/TitleBar/dune index 92818f3065..bf99a54951 100644 --- a/src/Feature/TitleBar/dune +++ b/src/Feature/TitleBar/dune @@ -2,7 +2,7 @@ (name Feature_TitleBar) (public_name Oni2.feature.titlebar) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.feature.contextMenu Oni2.feature.theme diff --git a/src/Model/dune b/src/Model/dune index 67583487d7..5a96c7f5c2 100644 --- a/src/Model/dune +++ b/src/Model/dune @@ -49,6 +49,6 @@ Oni2.feature.signature_help ReasonFuzz textmate - editor-core-types + Oni2.editor-core-types ) (preprocess (pps lwt_ppx ppx_deriving_yojson ppx_deriving.show))) diff --git a/src/Service/Clipboard/dune b/src/Service/Clipboard/dune index f3856b049e..73875c0c91 100644 --- a/src/Service/Clipboard/dune +++ b/src/Service/Clipboard/dune @@ -2,7 +2,7 @@ (name Service_Clipboard) (public_name Oni2.service.clipboard) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Revery isolinear diff --git a/src/Service/Extensions/dune b/src/Service/Extensions/dune index 35143affc6..8d06eae2fd 100644 --- a/src/Service/Extensions/dune +++ b/src/Service/Extensions/dune @@ -2,7 +2,7 @@ (name Service_Extensions) (public_name Oni2.service.extensions) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.exthost Oni2.service.net diff --git a/src/Service/Exthost/dune b/src/Service/Exthost/dune index 6a6b5c4055..be41739267 100644 --- a/src/Service/Exthost/dune +++ b/src/Service/Exthost/dune @@ -2,7 +2,7 @@ (name Service_Exthost) (public_name Oni2.service.exthost) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.exthost isolinear diff --git a/src/Service/Font/dune b/src/Service/Font/dune index 697fdcf3c4..901b42cc65 100644 --- a/src/Service/Font/dune +++ b/src/Service/Font/dune @@ -2,7 +2,7 @@ (name Service_Font) (public_name Oni2.service.font) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Revery isolinear diff --git a/src/Service/Net/dune b/src/Service/Net/dune index 66fe6d4a97..075ad4b6a7 100644 --- a/src/Service/Net/dune +++ b/src/Service/Net/dune @@ -3,7 +3,7 @@ (public_name Oni2.service.net) (inline_tests) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.service.os Revery diff --git a/src/Service/OS/dune b/src/Service/OS/dune index 9673a68075..0115f54eb2 100644 --- a/src/Service/OS/dune +++ b/src/Service/OS/dune @@ -2,7 +2,7 @@ (name Service_OS) (public_name Oni2.service.os) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Revery isolinear diff --git a/src/Service/Syntax/dune b/src/Service/Syntax/dune index adf78a6d59..1a0737e677 100644 --- a/src/Service/Syntax/dune +++ b/src/Service/Syntax/dune @@ -2,7 +2,7 @@ (name Service_Syntax) (public_name Oni2.service.syntax) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.syntax Oni2.syntax_client diff --git a/src/Service/Terminal/dune b/src/Service/Terminal/dune index e4e0de7c15..2bd6b3674f 100644 --- a/src/Service/Terminal/dune +++ b/src/Service/Terminal/dune @@ -2,7 +2,7 @@ (name Service_Terminal) (public_name Oni2.service.terminal) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core Oni2.exthost Revery diff --git a/src/Service/Vim/dune b/src/Service/Vim/dune index ec48acdc67..24a221c7b4 100644 --- a/src/Service/Vim/dune +++ b/src/Service/Vim/dune @@ -2,7 +2,7 @@ (name Service_Vim) (public_name Oni2.service.vim) (libraries - editor-core-types + Oni2.editor-core-types Oni2.core isolinear ) diff --git a/src/UI/dune b/src/UI/dune index 69889e64b9..73e06d9dae 100644 --- a/src/UI/dune +++ b/src/UI/dune @@ -26,6 +26,6 @@ Revery Revery.zed revery-terminal.lib - editor-core-types + Oni2.editor-core-types ppx_deriving.runtime )) diff --git a/src/editor-core-types/Index.re b/src/editor-core-types/Index.re new file mode 100644 index 0000000000..73241e4e27 --- /dev/null +++ b/src/editor-core-types/Index.re @@ -0,0 +1,30 @@ +[@deriving show({with_path: false})] +type t = int; // 0-based internally + +let zero = 0; + +let fromZeroBased = i => i; +let fromOneBased = i => + if (i == 0) { + raise(Invalid_argument("One-based index cannot be zero")); + } else { + i - 1; + }; + +let toZeroBased = i => i; +let toOneBased = i => i + 1; + +let equals = (==); + +let (==) = (==); +let (>) = (>); +let (>=) = (>=); +let (<) = (<); +let (<=) = (<=); + +let (+) = (+); +let (-) = (-); +let ( * ) = ( * ); +let (/) = (/); + +let toString = string_of_int; diff --git a/src/editor-core-types/Index.rei b/src/editor-core-types/Index.rei new file mode 100644 index 0000000000..7decd35336 --- /dev/null +++ b/src/editor-core-types/Index.rei @@ -0,0 +1,25 @@ +[@deriving show] +type t = pri int; + +let zero: t; + +let fromZeroBased: int => t; +let fromOneBased: int => t; + +let toZeroBased: t => int; +let toOneBased: t => int; + +let equals: (t, t) => bool; + +let (==): (t, t) => bool; +let (>): (t, t) => bool; +let (>=): (t, t) => bool; +let (<): (t, t) => bool; +let (<=): (t, t) => bool; + +let (+): (t, int) => t; +let (-): (t, int) => t; +let ( * ): (t, int) => t; +let (/): (t, int) => t; + +let toString: t => string; diff --git a/src/editor-core-types/Location.re b/src/editor-core-types/Location.re new file mode 100644 index 0000000000..e4f04c3544 --- /dev/null +++ b/src/editor-core-types/Location.re @@ -0,0 +1,14 @@ +[@deriving show({with_path: false})] +type t = { + line: Index.t, + column: Index.t, +}; + +let create = (~line, ~column) => {line, column}; + +let equals = (a, b) => Index.(a.line == b.line && a.column == b.column); + +let (==) = equals; + +let toString = ({line, column}) => + Printf.sprintf("%n,%n", (line :> int), (column :> int)); diff --git a/src/editor-core-types/Location.rei b/src/editor-core-types/Location.rei new file mode 100644 index 0000000000..d209620cea --- /dev/null +++ b/src/editor-core-types/Location.rei @@ -0,0 +1,12 @@ +[@deriving show] +type t = { + line: Index.t, + column: Index.t, +}; + +let create: (~line: Index.t, ~column: Index.t) => t; + +let equals: (t, t) => bool; +let (==): (t, t) => bool; + +let toString: t => string; diff --git a/src/editor-core-types/Range.re b/src/editor-core-types/Range.re new file mode 100644 index 0000000000..eb622da5c0 --- /dev/null +++ b/src/editor-core-types/Range.re @@ -0,0 +1,79 @@ +[@deriving show({with_path: false})] +type t = { + start: Location.t, + stop: Location.t, +}; + +let create = (~start, ~stop) => {start, stop}; + +let explode = (measure, range) => + if (range.start.line == range.stop.line) { + [range]; + } else { + let ranges = ref([]); + let pushRange = (~start, ~stop) => + ranges := [create(~start, ~stop), ...ranges^]; + + let i = ref(range.start.line); + while (i^ < range.stop.line) { + let startColumn = + i^ == range.start.line ? range.start.column : Index.zero; + let stopColumn = measure(i^) |> max(1) |> Index.fromOneBased; + + pushRange( + ~start=Location.create(~line=i^, ~column=startColumn), + ~stop=Location.create(~line=i^, ~column=stopColumn), + ); + + i := Index.(i^ + 1); + }; + + pushRange( + ~start=Location.create(~line=range.stop.line, ~column=Index.zero), + ~stop=Location.create(~line=range.stop.line, ~column=range.stop.column), + ); + + ranges^ |> List.rev; + }; + +let toHash = ranges => { + let hash = Hashtbl.create(100); + + List.iter( + range => { + let line = range.start.line; + let lineRanges = + switch (Hashtbl.find_opt(hash, line)) { + | Some(ranges) => ranges + | None => [] + }; + + Hashtbl.add(hash, line, [range, ...lineRanges]); + }, + ranges, + ); + + hash; +}; + +let equals = (a, b) => Location.(a.start == b.start && a.stop == b.stop); + +let contains = (position: Location.t, range) => { + ( + position.line == range.start.line + && position.column >= range.start.column + || position.line > range.start.line + ) + && ( + position.line == range.stop.line + && position.column <= range.stop.column + || position.line < range.stop.line + ); +}; + +let toString = ({start, stop}) => + Printf.sprintf( + "Range - start: %s end: %s", + Location.toString(start), + Location.toString(stop), + ); diff --git a/src/editor-core-types/Range.rei b/src/editor-core-types/Range.rei new file mode 100644 index 0000000000..83648b6a99 --- /dev/null +++ b/src/editor-core-types/Range.rei @@ -0,0 +1,30 @@ +[@deriving show] +type t = { + start: Location.t, + stop: Location.t, +}; + +let create: (~start: Location.t, ~stop: Location.t) => t; + +/* + * explode(range, measure) takes a Range.t and a measurement function (int => int), + * and expands a multiple-line range into a list of ranges, where there is + * a single range per-line. + * + * If the input range is a single line, a single item list with the input range + * will be returned. + */ +let explode: (Index.t => int, t) => list(t); + +/** + * [toHash(ranges)] takes a list [ranges] of [Range.t], and returns them as a + * a hash table, where the key is the start line of the [Range.t], + * and the value is the list of all ranges with that start line. + */ +let toHash: list(t) => Hashtbl.t(Index.t, list(t)); + +let equals: (t, t) => bool; + +let contains: (Location.t, t) => bool; + +let toString: t => string; diff --git a/src/editor-core-types/dune b/src/editor-core-types/dune new file mode 100644 index 0000000000..66fcb291c4 --- /dev/null +++ b/src/editor-core-types/dune @@ -0,0 +1,4 @@ +(library + (name EditorCoreTypes) + (public_name Oni2.editor-core-types) + (preprocess (pps ppx_deriving.show))) diff --git a/src/reason-libvim/dune b/src/reason-libvim/dune index 872f0e60fa..359ae78caf 100644 --- a/src/reason-libvim/dune +++ b/src/reason-libvim/dune @@ -8,7 +8,7 @@ (preprocess (pps ppx_deriving.show)) (libraries base - editor-core-types + Oni2.editor-core-types timber Revery.zed ppx_deriving.runtime diff --git a/src/reason-tree-sitter/dune b/src/reason-tree-sitter/dune index 3d8d793a1c..8d0174189e 100644 --- a/src/reason-tree-sitter/dune +++ b/src/reason-tree-sitter/dune @@ -5,7 +5,7 @@ (c_flags (:include c_flags.sexp)) (c_names bindings) (cxx_flags (:include cxx_flags.sexp)) - (libraries editor-core-types)) + (libraries Oni2.editor-core-types)) (rule (targets c_flags.sexp cxx_flags.sexp flags.sexp) diff --git a/test.esy.lock/index.json b/test.esy.lock/index.json index 457977dc87..cdecf3fdd3 100644 --- a/test.esy.lock/index.json +++ b/test.esy.lock/index.json @@ -1,5 +1,5 @@ { - "checksum": "6ae3b54a20c7864d87459152e22615c5", + "checksum": "5e8524c242a61726b3a1543f3764573d", "root": "Oni2@link-dev:./package.json", "node": { "yarn-pkg-config@github:esy-ocaml/yarn-pkg-config#db3a0b63883606dd57c54a7158d560d6cba8cd79@d41d8cd9": { @@ -803,23 +803,6 @@ "dependencies": [], "devDependencies": [] }, - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9": { - "id": - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9", - "name": "editor-core-types", - "version": "github:onivim/editor-core-types#6a8afaf", - "source": { - "type": "install", - "source": [ "github:onivim/editor-core-types#6a8afaf" ] - }, - "overrides": [], - "dependencies": [ - "refmterr@3.3.2@d41d8cd9", "ocaml@4.10.0@d41d8cd9", - "@opam/ppx_deriving@opam:4.5@d89f2934", - "@opam/dune@opam:2.5.0@e0bac278", "@esy-ocaml/reason@3.6.2@d41d8cd9" - ], - "devDependencies": [ "ocaml@4.10.0@d41d8cd9" ] - }, "debug@3.1.0@d41d8cd9": { "id": "debug@3.1.0@d41d8cd9", "name": "debug", @@ -966,9 +949,8 @@ "esy-sdl2@2.0.10008@d41d8cd9", "esy-oniguruma@github:onivim/esy-oniguruma#4698ce4@d41d8cd9", "esy-macdylibbundler@0.4.5@d41d8cd9", - "esy-angle-prebuilt@1.0.0@d41d8cd9", - "editor-core-types@github:onivim/editor-core-types#6a8afaf@d41d8cd9", - "axios@0.19.2@d41d8cd9", "@reason-native/rely@3.2.1@d41d8cd9", + "esy-angle-prebuilt@1.0.0@d41d8cd9", "axios@0.19.2@d41d8cd9", + "@reason-native/rely@3.2.1@d41d8cd9", "@reason-native-web/esy-openssl@1.1.1006@d41d8cd9", "@opam/yojson@github:onivim/yojson:yojson.opam#f480aef@d41d8cd9", "@opam/uutf@opam:1.0.2@4440868f", "@opam/uucp@opam:13.0.0@e9b515e0", diff --git a/test/Cli/dune b/test/Cli/dune index fb0977b811..0b55c93c6a 100644 --- a/test/Cli/dune +++ b/test/Cli/dune @@ -8,6 +8,6 @@ Oni_Core_Test rely.lib luv - editor-core-types + Oni2.editor-core-types unix )) diff --git a/test/Core/Utility/dune b/test/Core/Utility/dune index 2d9044d1c5..29fb3827bc 100644 --- a/test/Core/Utility/dune +++ b/test/Core/Utility/dune @@ -2,4 +2,4 @@ (name Oni_Core_Utility_Test) (library_flags (-linkall -g)) (modules (:standard)) - (libraries base Oni2.core rely.lib editor-core-types)) + (libraries base Oni2.core rely.lib Oni2.editor-core-types)) diff --git a/test/Core/dune b/test/Core/dune index 5f49616abe..b9aa9eeddf 100644 --- a/test/Core/dune +++ b/test/Core/dune @@ -9,5 +9,5 @@ fp rely.lib luv - editor-core-types + Oni2.editor-core-types )) diff --git a/test/Feature/Editor/dune b/test/Feature/Editor/dune index 70b2e20d79..bdcd560dea 100644 --- a/test/Feature/Editor/dune +++ b/test/Feature/Editor/dune @@ -2,4 +2,4 @@ (name Feature_Editor_Test) (library_flags (-linkall -g)) (modules (:standard)) - (libraries Oni2.core Oni2.feature.editor Oni_Core_Test rely.lib editor-core-types)) + (libraries Oni2.core Oni2.feature.editor Oni_Core_Test rely.lib Oni2.editor-core-types)) diff --git a/test/Feature/LanguageSupport/dune b/test/Feature/LanguageSupport/dune index abe28e7f88..6b8138033c 100644 --- a/test/Feature/LanguageSupport/dune +++ b/test/Feature/LanguageSupport/dune @@ -2,4 +2,4 @@ (name Feature_LanguageSupport_Test) (library_flags (-linkall -g)) (modules (:standard)) - (libraries Oni2.core Oni2.feature.language_support rely.lib editor-core-types)) + (libraries Oni2.core Oni2.feature.language_support rely.lib Oni2.editor-core-types)) diff --git a/test/Model/dune b/test/Model/dune index 0993d6d9e1..4df3e0d13f 100644 --- a/test/Model/dune +++ b/test/Model/dune @@ -2,4 +2,4 @@ (name Oni_Model_Test) (library_flags (-linkall -g)) (modules (:standard)) - (libraries libvim Oni2.core Oni2.model Oni_Core_Test rely.lib editor-core-types)) + (libraries libvim Oni2.core Oni2.model Oni_Core_Test rely.lib Oni2.editor-core-types)) diff --git a/test/OniUnitTestRunner.re b/test/OniUnitTestRunner.re index d21081c889..98b46a7fe2 100644 --- a/test/OniUnitTestRunner.re +++ b/test/OniUnitTestRunner.re @@ -17,6 +17,7 @@ Service_OS_Test.TestFramework.cli(); Vim.init(); Libvim_Test.TestFramework.cli(); +EditorCoreTypes_Test.TestFramework.cli(); EditorInput_Test.TestFramework.cli(); Exthost_Transport_Test.TestFramework.cli(); Exthost_Test.TestFramework.cli(); diff --git a/test/OniUnitTestRunnerCI.re b/test/OniUnitTestRunnerCI.re index de8ed4eb67..0f2a4d3a07 100644 --- a/test/OniUnitTestRunnerCI.re +++ b/test/OniUnitTestRunnerCI.re @@ -46,6 +46,13 @@ Feature_LanguageSupport_Test.TestFramework.run( ), ); +EditorCoreTypes_Test.TestFramework.run( + Rely.RunConfig.withReporters( + [Default, JUnit("./junit.xml")], + Rely.RunConfig.initialize(), + ), +); + EditorInput_Test.TestFramework.run( Rely.RunConfig.withReporters( [Default, JUnit("./junit.xml")], diff --git a/test/Service/Net/dune b/test/Service/Net/dune index cfa69aef9a..bfbd818fd2 100644 --- a/test/Service/Net/dune +++ b/test/Service/Net/dune @@ -2,4 +2,4 @@ (name Service_Net_Test) (library_flags (-linkall -g)) (modules (:standard)) - (libraries Oni2.core Oni2.service.net Oni_Core_Test rely.lib editor-core-types)) + (libraries Oni2.core Oni2.service.net Oni_Core_Test rely.lib Oni2.editor-core-types)) diff --git a/test/Service/OS/dune b/test/Service/OS/dune index fb843debb3..805b8c30e6 100644 --- a/test/Service/OS/dune +++ b/test/Service/OS/dune @@ -2,4 +2,4 @@ (name Service_OS_Test) (library_flags (-linkall -g)) (modules (:standard)) - (libraries Oni2.core Oni2.service.os Oni_Core_Test rely.lib editor-core-types)) + (libraries Oni2.core Oni2.service.os Oni_Core_Test rely.lib Oni2.editor-core-types)) diff --git a/test/dune b/test/dune index 554fad3cf7..a0e34f1918 100644 --- a/test/dune +++ b/test/dune @@ -16,6 +16,7 @@ Service_Extensions_Test Service_Net_Test Service_OS_Test + EditorCoreTypes_Test EditorInput_Test Exthost_Transport_Test Exthost_Test @@ -146,6 +147,7 @@ Service_Extensions_Test Service_Net_Test Service_OS_Test + EditorCoreTypes_Test EditorInput_Test Exthost_Transport_Test Exthost_Test diff --git a/test/editor-core-types/Helpers.re b/test/editor-core-types/Helpers.re new file mode 100644 index 0000000000..9438d90bf2 --- /dev/null +++ b/test/editor-core-types/Helpers.re @@ -0,0 +1,22 @@ +open EditorCoreTypes; + +let validateRange = + ( + expect: RelyInternal__Test.matchers(unit), + actual: Range.t, + expected: Range.t, + ) => { + expect.int((actual.start.line :> int)).toBe((expected.start.line :> int)); + expect.int((actual.stop.line :> int)).toBe((expected.stop.line :> int)); + expect.int((actual.start.column :> int)).toBe( + (expected.start.column :> int), + ); + expect.int((actual.stop.column :> int)).toBe( + (expected.stop.column :> int), + ); +}; + +let validateRanges = + (expect: RelyInternal__Test.matchers(unit), actual, expected) => { + List.iter2(validateRange(expect), actual, expected); +}; diff --git a/test/editor-core-types/RangeTests.re b/test/editor-core-types/RangeTests.re new file mode 100644 index 0000000000..2a37504e6f --- /dev/null +++ b/test/editor-core-types/RangeTests.re @@ -0,0 +1,64 @@ +open EditorCoreTypes; +open TestFramework; + +open Helpers; + +let constantMeasure = (length, _: Index.t) => length; + +let createRange = (startLine, startColumn, stopLine, stopColumn) => + Range.create( + ~start= + Location.create( + ~line=Index.fromZeroBased(startLine), + ~column=Index.fromZeroBased(startColumn), + ), + ~stop= + Location.create( + ~line=Index.fromZeroBased(stopLine), + ~column=Index.fromZeroBased(stopColumn), + ), + ); + +describe("Range", ({describe, _}) => + describe("explode", ({test, _}) => { + test( + "returns same range when start line/endline are the same", + ({expect, _}) => { + let emptyRange = + Range.create( + ~start=Location.create(~line=Index.zero, ~column=Index.zero), + ~stop=Location.create(~line=Index.zero, ~column=Index.zero), + ); + + validateRanges( + expect, + Range.explode(constantMeasure(1), emptyRange), + [emptyRange], + ); + }); + + test("simple two-line case", ({expect, _}) => { + let range = createRange(1, 5, 2, 2); + + validateRanges( + expect, + Range.explode(constantMeasure(10), range), + [createRange(1, 5, 1, 9), createRange(2, 0, 2, 2)], + ); + }); + + test("uses range function", ({expect, _}) => { + let range = createRange(1, 5, 3, 2); + + validateRanges( + expect, + Range.explode(constantMeasure(10), range), + [ + createRange(1, 5, 1, 9), + createRange(2, 0, 2, 9), + createRange(3, 0, 3, 2), + ], + ); + }); + }) +); diff --git a/test/editor-core-types/TestFramework.re b/test/editor-core-types/TestFramework.re new file mode 100644 index 0000000000..7bd3a76d29 --- /dev/null +++ b/test/editor-core-types/TestFramework.re @@ -0,0 +1,7 @@ +include Rely.Make({ + let config = + Rely.TestFrameworkConfig.initialize({ + snapshotDir: "./__snapshots__", + projectDir: "", + }); +}); diff --git a/test/editor-core-types/dune b/test/editor-core-types/dune new file mode 100644 index 0000000000..b912beea68 --- /dev/null +++ b/test/editor-core-types/dune @@ -0,0 +1,6 @@ +(library + (name EditorCoreTypes_Test) + (flags (:standard (-w -39))) + (ocamlopt_flags -linkall -g) + (libraries Oni2.editor-core-types rely.lib) + (modules (:standard)))