Skip to content

Commit

Permalink
refactor(monorepo): editor-core-types (onivim#2315)
Browse files Browse the repository at this point in the history
With onivim#2312 and onivim#2313 - moving in `reason-tree-sitter` and `editor-input` - we can now move `editor-core-types` into Onivim proper.

The reason behind this is to update some of the common types - like `Index.t` and `Range.t` - they are not quite setup in a way where we can fully benefit from the type-system. In particular, we don't have typing around byte position vs UTF-8 character position vs screen column - they are just all ints or `Index.t`s. We should be able to leverage the type-system for this, and have auxiliary types, like `ByteRange.t`, so that we can be explicit in our APIs to document whether a function expects a byte index, character index, etc, and have it enforced by the compiler.
  • Loading branch information
bryphe authored Aug 18, 2020
1 parent bb94062 commit 43b3aa3
Show file tree
Hide file tree
Showing 54 changed files with 347 additions and 122 deletions.
23 changes: 2 additions & 21 deletions bench.esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 2 additions & 21 deletions esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 2 additions & 21 deletions integrationtest.esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Components/dune
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
Oni2.feature.theme
Rench
Revery
editor-core-types
Oni2.editor-core-types
isolinear
))
2 changes: 1 addition & 1 deletion src/Core/Kernel/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
2 changes: 1 addition & 1 deletion src/Core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
yojson
ppx_deriving.runtime
ppx_deriving_yojson.runtime
editor-core-types
Oni2.editor-core-types
timber
ReasonFuzz
decoders-yojson
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/Editor/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/LanguageSupport/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/Menus/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/SCM/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/Search/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/SignatureHelp/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/Sneak/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/StatusBar/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/Syntax/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/Terminal/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/TitleBar/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Model/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
2 changes: 1 addition & 1 deletion src/Service/Clipboard/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name Service_Clipboard)
(public_name Oni2.service.clipboard)
(libraries
editor-core-types
Oni2.editor-core-types
Oni2.core
Revery
isolinear
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Extensions/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Exthost/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Font/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name Service_Font)
(public_name Oni2.service.font)
(libraries
editor-core-types
Oni2.editor-core-types
Oni2.core
Revery
isolinear
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Net/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Service/OS/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name Service_OS)
(public_name Oni2.service.os)
(libraries
editor-core-types
Oni2.editor-core-types
Oni2.core
Revery
isolinear
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Syntax/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Terminal/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Vim/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(name Service_Vim)
(public_name Oni2.service.vim)
(libraries
editor-core-types
Oni2.editor-core-types
Oni2.core
isolinear
)
Expand Down
2 changes: 1 addition & 1 deletion src/UI/dune
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
Revery
Revery.zed
revery-terminal.lib
editor-core-types
Oni2.editor-core-types
ppx_deriving.runtime
))
30 changes: 30 additions & 0 deletions src/editor-core-types/Index.re
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 43b3aa3

Please sign in to comment.