Compare commits
87 Commits
4e25b28bbe
...
v0.0.3-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
410222b82a
|
|||
|
f93afc0d14
|
|||
|
86d5b7a021
|
|||
|
78949bc770
|
|||
|
17a04bdddc
|
|||
|
eafed64bea
|
|||
|
9757a8db31
|
|||
|
cef357ffdc
|
|||
|
515d5559a7
|
|||
|
1312c09501
|
|||
|
b018877c03
|
|||
|
e6f51d69b6
|
|||
|
6abdefa808
|
|||
|
cca0177929
|
|||
|
6dc0813b49
|
|||
|
81da75dc15
|
|||
|
fd894e4e9f
|
|||
|
b5c49f4277
|
|||
|
c9324c13aa
|
|||
|
c8db7b14a3
|
|||
|
d0e811904c
|
|||
|
1fda5bf246
|
|||
|
04cce25bf2
|
|||
|
9ed640c88e
|
|||
|
bb87ae32f9
|
|||
|
f2f176e8c8
|
|||
|
cdddb35d7c
|
|||
|
e37d291e1d
|
|||
|
78bf2d666d
|
|||
|
b20702928a
|
|||
|
3f2046bf9f
|
|||
|
672e1a5c4e
|
|||
|
ae7bb754ae
|
|||
|
9bd4145d8c
|
|||
|
8f69ee487b
|
|||
|
4134c4d96d
|
|||
|
7d35799394
|
|||
|
2c1e69181a
|
|||
|
b2a64f219f
|
|||
|
e9da17eb34
|
|||
|
a905e333fc
|
|||
|
ac04754318
|
|||
|
0390a1bc5d
|
|||
|
dc507dfc23
|
|||
|
26e0b06e24
|
|||
|
235eafb01c
|
|||
|
04179d1a4e
|
|||
|
c7068d33d7
|
|||
|
6108f78be3
|
|||
|
bfaba81317
|
|||
|
a38ba1f813
|
|||
|
655f0e7d77
|
|||
|
9ff3a32abd
|
|||
|
b6e40ae1a6
|
|||
|
f3c87431a3
|
|||
|
69b981097e
|
|||
|
659628835d
|
|||
|
a10dd92249
|
|||
|
85d4039a5e
|
|||
|
43f443e128
|
|||
|
a12e2fb1c4
|
|||
|
7307387f64
|
|||
|
8002012705
|
|||
|
d5145d88a7
|
|||
|
f347f50dbe
|
|||
| f764c78c6b | |||
|
4f19c2f6c1
|
|||
|
d82389bc42
|
|||
|
5fae2f3bb6
|
|||
|
aa25bf0ac3
|
|||
|
628000f851
|
|||
|
5153770ee9
|
|||
|
a59111162c
|
|||
|
d8c281d7d7
|
|||
|
d9ebf83588
|
|||
|
e83cc6cf02
|
|||
|
38839408b1
|
|||
|
d5f5dd21b0
|
|||
|
ce06ca8057
|
|||
|
dad7d844ca
|
|||
|
e6ce95a1d4
|
|||
|
06c7b7dfaa
|
|||
|
fd70a40a49
|
|||
|
39542bac33
|
|||
|
ce74e75f04
|
|||
|
7349cfd00a
|
|||
|
17e8521f6a
|
8
.clangd
Normal file
8
.clangd
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [
|
||||||
|
-I/home/syed/main/crib/include,
|
||||||
|
-I/home/syed/main/crib/libs,
|
||||||
|
-std=c++23
|
||||||
|
]
|
||||||
|
Remove: []
|
||||||
|
Compiler: clang++
|
||||||
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,2 +1 @@
|
|||||||
/libs/unicode_width/** linguist-vendored
|
/libs/** linguist-vendored
|
||||||
*.scm linguist-language=Tree-sitter-Query
|
|
||||||
|
|||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,13 +3,18 @@
|
|||||||
*.a
|
*.a
|
||||||
*.o
|
*.o
|
||||||
*.so
|
*.so
|
||||||
|
!libs/libruby/libruby.so
|
||||||
*.yml
|
*.yml
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
samples/t_*
|
samples/tmp*
|
||||||
|
|
||||||
build
|
build
|
||||||
bin
|
bin
|
||||||
|
|
||||||
|
.thinlto-cache/
|
||||||
|
Gemfile*
|
||||||
|
.ruby-lsp/
|
||||||
|
|
||||||
__old__
|
__old__
|
||||||
|
|||||||
64
.gitmodules
vendored
64
.gitmodules
vendored
@@ -2,67 +2,3 @@
|
|||||||
path = libs/libgrapheme
|
path = libs/libgrapheme
|
||||||
url = git://git.suckless.org/libgrapheme
|
url = git://git.suckless.org/libgrapheme
|
||||||
ignore = dirty
|
ignore = dirty
|
||||||
|
|
||||||
; tree-sitter
|
|
||||||
[submodule "libs/tree-sitter"]
|
|
||||||
path = libs/tree-sitter
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter.git
|
|
||||||
ignore = dirty
|
|
||||||
|
|
||||||
; Tree-sitter languages
|
|
||||||
[submodule "libs/tree-sitter-ruby"]
|
|
||||||
path = libs/tree-sitter-ruby
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-ruby.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-c"]
|
|
||||||
path = libs/tree-sitter-c
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-c.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-cpp"]
|
|
||||||
path = libs/tree-sitter-cpp
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-cpp.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-css"]
|
|
||||||
path = libs/tree-sitter-css
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-css.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-html"]
|
|
||||||
path = libs/tree-sitter-html
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-html.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-javascript"]
|
|
||||||
path = libs/tree-sitter-javascript
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-javascript.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-json"]
|
|
||||||
path = libs/tree-sitter-json
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-json.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-python"]
|
|
||||||
path = libs/tree-sitter-python
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-python.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-haskell"]
|
|
||||||
path = libs/tree-sitter-haskell
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-haskell.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-go"]
|
|
||||||
path = libs/tree-sitter-go
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-go.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-bash"]
|
|
||||||
path = libs/tree-sitter-bash
|
|
||||||
url = https://github.com/tree-sitter/tree-sitter-bash.git
|
|
||||||
ignore = dirty
|
|
||||||
[submodule "libs/tree-sitter-markdown"]
|
|
||||||
path = libs/tree-sitter-markdown
|
|
||||||
url = https://github.com/tree-sitter-grammars/tree-sitter-markdown
|
|
||||||
[submodule "libs/tree-sitter-make"]
|
|
||||||
path = libs/tree-sitter-make
|
|
||||||
url = https://github.com/tree-sitter-grammars/tree-sitter-make
|
|
||||||
[submodule "libs/tree-sitter-lua"]
|
|
||||||
path = libs/tree-sitter-lua
|
|
||||||
url = https://github.com/tree-sitter-grammars/tree-sitter-lua
|
|
||||||
[submodule "libs/tree-sitter-fish"]
|
|
||||||
path = libs/tree-sitter-fish
|
|
||||||
url = https://github.com/ram02z/tree-sitter-fish
|
|
||||||
|
|||||||
92
Makefile
92
Makefile
@@ -1,41 +1,56 @@
|
|||||||
SRC_DIR := src
|
SRC_DIR := src
|
||||||
BIN_DIR := bin
|
BIN_DIR := bin
|
||||||
OBJ_DIR := build
|
OBJ_DIR := build
|
||||||
|
INCLUDE_DIR := include
|
||||||
|
|
||||||
TARGET_DEBUG := $(BIN_DIR)/crib-dbg
|
TARGET_DEBUG := $(BIN_DIR)/crib-dbg
|
||||||
TARGET_RELEASE := $(BIN_DIR)/crib
|
TARGET_RELEASE := $(BIN_DIR)/crib
|
||||||
|
|
||||||
CCACHE := ccache
|
PCH_DEBUG := $(OBJ_DIR)/debug/pch.h.gch
|
||||||
CXX_DEBUG := $(CCACHE) g++
|
PCH_RELEASE := $(OBJ_DIR)/release/pch.h.gch
|
||||||
CXX_RELEASE := $(CCACHE) clang++
|
|
||||||
|
|
||||||
CFLAGS_DEBUG := -std=c++20 -Wall -Wextra -O0 -fno-inline -gsplit-dwarf -g -fsanitize=address -fno-omit-frame-pointer
|
GENERATED_HEADER := $(INCLUDE_DIR)/scripting/ruby_compiled.h
|
||||||
CFLAGS_RELEASE := -std=c++20 -O3 -march=native -flto=thin \
|
|
||||||
-fno-exceptions -fno-rtti -fstrict-aliasing -ffast-math -funroll-loops \
|
CCACHE := ccache
|
||||||
|
CXX := $(CCACHE) clang++
|
||||||
|
CC := $(CCACHE) musl-clang
|
||||||
|
|
||||||
|
CFLAGS_DEBUG :=\
|
||||||
|
-std=c++20 -Wall -Wextra \
|
||||||
|
-O0 -fno-inline -gsplit-dwarf \
|
||||||
|
-g -fno-omit-frame-pointer \
|
||||||
|
-Wno-unused-command-line-argument \
|
||||||
|
-fsanitize=address \
|
||||||
|
-I./include -I./libs
|
||||||
|
|
||||||
|
CFLAGS_RELEASE :=\
|
||||||
|
-static --target=x86_64-linux-musl \
|
||||||
|
-std=c++20 -O3 -march=x86-64 -mtune=generic \
|
||||||
|
-fno-rtti \
|
||||||
|
-ffast-math -flto=thin \
|
||||||
|
-fvisibility=hidden \
|
||||||
-fomit-frame-pointer -DNDEBUG -s \
|
-fomit-frame-pointer -DNDEBUG -s \
|
||||||
-mllvm -inline-threshold=10000 \
|
|
||||||
-mllvm -vectorize-loops \
|
-mllvm -vectorize-loops \
|
||||||
-mllvm -force-vector-width=8 \
|
-Wno-unused-command-line-argument \
|
||||||
-mllvm -unroll-threshold=500000
|
-I./include -I./libs
|
||||||
|
|
||||||
|
PCH_CFLAGS_DEBUG := $(CFLAGS_DEBUG) -x c++-header
|
||||||
|
PCH_CFLAGS_RELEASE := $(CFLAGS_RELEASE) -x c++-header
|
||||||
|
|
||||||
UNICODE_SRC := $(wildcard libs/unicode_width/*.c)
|
UNICODE_SRC := $(wildcard libs/unicode_width/*.c)
|
||||||
|
|
||||||
UNICODE_OBJ_DEBUG := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/debug/unicode_width/%.o,$(UNICODE_SRC))
|
UNICODE_OBJ_DEBUG := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/debug/unicode_width/%.o,$(UNICODE_SRC))
|
||||||
UNICODE_OBJ_RELEASE := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/release/unicode_width/%.o,$(UNICODE_SRC))
|
UNICODE_OBJ_RELEASE := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/release/unicode_width/%.o,$(UNICODE_SRC))
|
||||||
|
|
||||||
TREE_SITTER_LIBS := $(wildcard libs/tree-sitter-*/libtree-sitter*.a)
|
LIBS_RELEASE := \
|
||||||
FISH_OBJ_PARSER := libs/tree-sitter-fish/build/Release/obj.target/tree_sitter_fish_binding/src/parser.o
|
|
||||||
FISH_OBJ_SCANNER := libs/tree-sitter-fish/build/Release/obj.target/tree_sitter_fish_binding/src/scanner.o
|
|
||||||
|
|
||||||
LIBS := \
|
|
||||||
libs/libgrapheme/libgrapheme.a \
|
libs/libgrapheme/libgrapheme.a \
|
||||||
libs/tree-sitter/libtree-sitter.a \
|
-Wl,-Bstatic,--gc-sections -lpcre2-8 -lmruby
|
||||||
$(TREE_SITTER_LIBS) \
|
|
||||||
$(FISH_OBJ_PARSER) \
|
|
||||||
$(FISH_OBJ_SCANNER) \
|
|
||||||
-lpcre2-8 -lmagic
|
|
||||||
|
|
||||||
SRC := $(wildcard $(SRC_DIR)/*.cc)
|
LIBS_DEBUG := \
|
||||||
|
libs/libgrapheme/libgrapheme.a \
|
||||||
|
-Wl,-Bdynamic -lpcre2-8 -lmruby
|
||||||
|
|
||||||
|
SRC := $(wildcard $(SRC_DIR)/**/*.cc) $(wildcard $(SRC_DIR)/*.cc)
|
||||||
OBJ_DEBUG := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/debug/%.o,$(SRC))
|
OBJ_DEBUG := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/debug/%.o,$(SRC))
|
||||||
OBJ_RELEASE := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/release/%.o,$(SRC))
|
OBJ_RELEASE := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/release/%.o,$(SRC))
|
||||||
|
|
||||||
@@ -50,29 +65,40 @@ test: $(TARGET_DEBUG)
|
|||||||
|
|
||||||
release: $(TARGET_RELEASE)
|
release: $(TARGET_RELEASE)
|
||||||
|
|
||||||
$(TARGET_DEBUG): $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG)
|
$(GENERATED_HEADER): $(INCLUDE_DIR)/syntax/tokens.def $(INCLUDE_DIR)/scripting/libcrib.rb src/ruby_compile.sh
|
||||||
mkdir -p $(BIN_DIR)
|
src/ruby_compile.sh
|
||||||
$(CXX_DEBUG) $(CFLAGS_DEBUG) -o $@ $^ $(LIBS)
|
|
||||||
|
|
||||||
$(TARGET_RELEASE): $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE)
|
$(PCH_DEBUG): $(INCLUDE_DIR)/pch.h
|
||||||
mkdir -p $(BIN_DIR)
|
|
||||||
$(CXX_RELEASE) $(CFLAGS_RELEASE) -o $@ $^ $(LIBS)
|
|
||||||
|
|
||||||
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.cc
|
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(CXX_DEBUG) $(CFLAGS_DEBUG) -MMD -MP -c $< -o $@
|
$(CXX) $(PCH_CFLAGS_DEBUG) -o $@ $<
|
||||||
|
|
||||||
$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc
|
$(PCH_RELEASE): $(INCLUDE_DIR)/pch.h
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(CXX_RELEASE) $(CFLAGS_RELEASE) -MMD -MP -c $< -o $@
|
$(CXX) $(PCH_CFLAGS_RELEASE) -o $@ $<
|
||||||
|
|
||||||
|
$(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG)
|
||||||
|
mkdir -p $(BIN_DIR)
|
||||||
|
$(CXX) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG) $(LIBS_DEBUG)
|
||||||
|
|
||||||
|
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE)
|
||||||
|
mkdir -p $(BIN_DIR)
|
||||||
|
$(CXX) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE) $(LIBS_RELEASE)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.cc $(PCH_DEBUG) $(GENERATED_HEADER)
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CXX) $(CFLAGS_DEBUG) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE) $(GENERATED_HEADER)
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CXX) $(CFLAGS_RELEASE) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
$(OBJ_DIR)/debug/unicode_width/%.o: libs/unicode_width/%.c
|
$(OBJ_DIR)/debug/unicode_width/%.o: libs/unicode_width/%.c
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(CXX_DEBUG) $(CFLAGS_DEBUG) -MMD -MP -c $< -o $@
|
$(CC) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
$(OBJ_DIR)/release/unicode_width/%.o: libs/unicode_width/%.c
|
$(OBJ_DIR)/release/unicode_width/%.o: libs/unicode_width/%.c
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(CXX_RELEASE) $(CFLAGS_RELEASE) -MMD -MP -c $< -o $@
|
$(CC) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
DEP_DEBUG += $(UNICODE_OBJ_DEBUG:.o=.d)
|
DEP_DEBUG += $(UNICODE_OBJ_DEBUG:.o=.d)
|
||||||
DEP_RELEASE += $(UNICODE_OBJ_RELEASE:.o=.d)
|
DEP_RELEASE += $(UNICODE_OBJ_RELEASE:.o=.d)
|
||||||
|
|||||||
200
README.md
200
README.md
@@ -1,19 +1,191 @@
|
|||||||
Copyright 2025 Syed Daanish
|
Copyright 2025 Syed Daanish
|
||||||
|
|
||||||
# Crib
|
# Crib - a text editor
|
||||||
|
|
||||||
A TUI IDE.
|
### About
|
||||||
|
|
||||||
# TODO
|
Crib is a TUI based text editor built primaririly for personal use.<br>
|
||||||
|
Crib has a vim-style editor modes system but navigation and shortcuts are very different.<br>
|
||||||
|
It supports superfast incremental syntax highlighting.<br>
|
||||||
|
And LSP for auto-completion, diagnostics, hover docs etc.<br>
|
||||||
|
It aims to be complete general purpose IDE.<br>
|
||||||
|
(It is still very much a work in progress so a lot of things may seem incomplete)<br>
|
||||||
|
For now it is just a single file editor. I plan to add a multi-file support with file pickers and tabs soon.<br>
|
||||||
|
|
||||||
- [ ] Add support for text selection (slect range / all).
|
## Installation
|
||||||
- [ ] Add support for delete key.
|
|
||||||
- [ ] Add support for copy/cut/paste.
|
Binary can be installed with the following command:
|
||||||
- [ ] Add mouse support.
|
|
||||||
- [ ] Add modes for editing - insert, select, normal, etc.
|
```bash
|
||||||
- [ ] Add folding support.
|
curl https://syedm.dev/crib | sh
|
||||||
- [ ] Add feature where doing enter uses tree-sitter to add newline with indentation.
|
```
|
||||||
1. it should also put stuff like `}` on the next line.
|
|
||||||
- [ ] Add support for brackets/quotes to auto-close.
|
It requires `libmagic` to be installed (most systems have it preinstalled).<br>
|
||||||
- [ ] Add scm files for all the supported languages. (2/14) Done.
|
Currently only for Linux.<br>
|
||||||
- [ ] Add support for wide characters with wrapping.
|
*Tested with arch linux and ubuntu*<br>
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
### Get started
|
||||||
|
|
||||||
|
Make sure the repo is cloned with submodules to get `libgrapheme`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone --recurse-submodules https://git.syedm.dev/SyedM/crib.git
|
||||||
|
```
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
#### System-wide libraries
|
||||||
|
|
||||||
|
Make sure you have the following dependencies installed (apart from the standard C++ libraries):
|
||||||
|
|
||||||
|
* **[nlohmann/json](https://github.com/nlohmann/json)**
|
||||||
|
Install it via your package manager. Once installed, the header should be available as:
|
||||||
|
```cpp
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
```
|
||||||
|
|
||||||
|
* **[PCRE2](https://github.com/PCRE2Project/pcre2)**
|
||||||
|
Install the library to use its headers:
|
||||||
|
```cpp
|
||||||
|
#include <pcre2.h>
|
||||||
|
```
|
||||||
|
|
||||||
|
* **[mruby](https://github.com/mruby/mruby)**
|
||||||
|
Install it via your package manager. Once installed, the header should be available as:
|
||||||
|
```cpp
|
||||||
|
#include <mruby.h>
|
||||||
|
```
|
||||||
|
|
||||||
|
It also uses `xclip` at runtime for copying/pasting *(TODO: make it os portable)*.
|
||||||
|
And any modern terminal should work fine - preferably `kitty` or `wezterm`.<br>
|
||||||
|
|
||||||
|
#### `./libs` folder
|
||||||
|
|
||||||
|
Some other dependancies are added as submodules or copied.<br>
|
||||||
|
- `unicode_width` is compiled by the makefile so nothing to do there.<br>
|
||||||
|
- `libgrapheme` needs to be compiled using `make` in it's folder.<br>
|
||||||
|
|
||||||
|
#### LSPs
|
||||||
|
|
||||||
|
Lsp's are defined in the `libcrib.rb` file and you can use your `config/main.rb` file to add more.<br>
|
||||||
|
|
||||||
|
The following lsp's are added by default and can be installed anywhere in your `$PATH`<br>
|
||||||
|
|
||||||
|
* [clangd](https://clangd.llvm.org/)
|
||||||
|
* [ruby-lsp](https://shopify.github.io/ruby-lsp/)
|
||||||
|
* [bash-language-server](https://github.com/bash-lsp/bash-language-server)
|
||||||
|
* [vscode-css-language-server](https://github.com/hrsh7th/vscode-langservers-extracted)
|
||||||
|
* [vscode-json-language-server](https://github.com/hrsh7th/vscode-langservers-extracted)
|
||||||
|
* [fish-lsp](https://github.com/ndonfris/fish-lsp)
|
||||||
|
* [gopls](https://pkg.go.dev/golang.org/x/tools/gopls)
|
||||||
|
* [haskell-language-server](https://github.com/haskell/haskell-language-server)
|
||||||
|
* [emmet-language-server](https://github.com/olrtg/emmet-language-server)
|
||||||
|
* [typescript-language-server](https://github.com/typescript-language-server/typescript-language-server)
|
||||||
|
* [lua-language-server](https://github.com/LuaLS/lua-language-server)
|
||||||
|
* [pyright-langserver](https://github.com/microsoft/pyright)
|
||||||
|
* [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer)
|
||||||
|
* [intelephense](https://intelephense.com/)
|
||||||
|
* [marksman](https://github.com/artempyanykh/marksman)
|
||||||
|
* [nginx-language-server](https://github.com/pappasam/nginx-language-server)
|
||||||
|
* [taplo](https://taplo.tamasfe.dev/)
|
||||||
|
* [yaml-language-server](https://github.com/redhat-developer/yaml-language-server)
|
||||||
|
* [sqls](https://github.com/sqls-server/sqls)
|
||||||
|
* [make-language-server](https://github.com/Freed-Wu/autotools-language-server)
|
||||||
|
|
||||||
|
> As it is still in development, some of these may not work as expected or that well.<br>
|
||||||
|
> It should work even if the lsp is not installed but lsp features will not work.<br>
|
||||||
|
|
||||||
|
#### Compiler
|
||||||
|
|
||||||
|
`clang++` should work fine but `c++23+` is required.<br>
|
||||||
|
Can remove `ccache` if you want from the makefile.<br>
|
||||||
|
|
||||||
|
#### Compliling
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make release
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running
|
||||||
|
|
||||||
|
Preferably add the `bin` folder to PATH or move `bin/crib` to somewhere in PATH.<br>
|
||||||
|
For some LSP's to work properly `crib` needs to be run from the root folder of the project. *To be fixed*<br>
|
||||||
|
then do -<br>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
crib ./filename.ext
|
||||||
|
```
|
||||||
|
|
||||||
|
*If `filename.ext` does not exist, it will be created*<br>
|
||||||
|
|
||||||
|
## Keybindings
|
||||||
|
|
||||||
|
TODO: add keybind information on how to set in `config/main.rb`
|
||||||
|
and default / unchangeable keybinds
|
||||||
|
|
||||||
|
## Features Implemented
|
||||||
|
|
||||||
|
#### Core workflow:
|
||||||
|
- NORMAL / INSERT / SELECT / RUNNER / JUMPER modes
|
||||||
|
- full mouse support for scrolling and multi-click word/line selection.
|
||||||
|
- Double click to select word
|
||||||
|
- Triple click to select line
|
||||||
|
|
||||||
|
#### Core editing tools:
|
||||||
|
- indent/dedent
|
||||||
|
- move lines up/down
|
||||||
|
- folding on a selected range
|
||||||
|
- yank/cut/paste via system clipboard
|
||||||
|
- per-language smart auto-indent on new line insert
|
||||||
|
- bracket/quote auto-pairing
|
||||||
|
- hooks jumping (bookmarking)
|
||||||
|
- color hex code highlighting
|
||||||
|
- current line highlighting
|
||||||
|
- all instances of current word under cursor highlighting
|
||||||
|
|
||||||
|
#### syntax highlighting and filetype detection for:
|
||||||
|
- ruby
|
||||||
|
<!-- TODO: -->
|
||||||
|
<!-- - bash -->
|
||||||
|
<!-- - c/cpp (and headers) -->
|
||||||
|
<!-- - css -->
|
||||||
|
<!-- - fish -->
|
||||||
|
<!-- - go/gomod -->
|
||||||
|
<!-- - haskell -->
|
||||||
|
<!-- - html/erb -->
|
||||||
|
<!-- - javascript -->
|
||||||
|
<!-- - typescript/tsx -->
|
||||||
|
<!-- - json/jsonc -->
|
||||||
|
<!-- - lua -->
|
||||||
|
<!-- - python -->
|
||||||
|
<!-- - rust -->
|
||||||
|
<!-- - php -->
|
||||||
|
<!-- - markdown -->
|
||||||
|
<!-- - nginx -->
|
||||||
|
<!-- - toml -->
|
||||||
|
<!-- - yaml -->
|
||||||
|
<!-- - sql -->
|
||||||
|
<!-- - make -->
|
||||||
|
<!-- - gdscript -->
|
||||||
|
<!-- - man pages -->
|
||||||
|
<!-- - diff/patch -->
|
||||||
|
<!-- - gitattributes/gitignore -->
|
||||||
|
<!-- - tree-sitter queries -->
|
||||||
|
<!-- - regex -->
|
||||||
|
<!-- - ini -->
|
||||||
|
|
||||||
|
#### LSP-powered features:
|
||||||
|
- diagnostics
|
||||||
|
- autocompletion
|
||||||
|
- hover docs
|
||||||
|
- formatting support
|
||||||
|
- Full file formatting on save
|
||||||
|
- Ontype formatting when inserting special characters defined by the language server
|
||||||
|
- *(few lsp's actually support this - try to configure a few more which can but need configuration and for others need to add support for external formatters)*
|
||||||
|
- A list of some lsp's can be found [here](#lsps).
|
||||||
|
- Any lsp can be added to the `config/main.rb` file.
|
||||||
|
- Though not all might work well. Open an issue if you find a lsp that doesn't work well.
|
||||||
|
|
||||||
|
**A lot lot more to come**
|
||||||
|
|||||||
125
TODO.md
Normal file
125
TODO.md
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
Copyright 2025 Syed Daanish
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
##### BTW Check each lsp with each of the features implemented
|
||||||
|
|
||||||
|
* [ ] Make a proper qeued system for bar contents from ruby
|
||||||
|
* [ ] Allow clipbaord setting & alpha in ini files
|
||||||
|
* [ ] Make warning before ctrl+q for saving
|
||||||
|
* [ ] **LSP Bug:** Check why `fish-lsp` is behaving so off with completions filtering.
|
||||||
|
* [ ] **Line move:** fix the move line functions to work without the calculations from folds as folds are removed.
|
||||||
|
* [ ] **Editor Indentation Fix:** - Main : merger indentation with the parser for more accurate results.
|
||||||
|
* [ ] Fix bug where enter at start of line with ending type crashes
|
||||||
|
* [ ] Keep cache of language maps in engine to reduce lookup time.
|
||||||
|
* [ ] In indents add function to support tab which indents if before any content and inserts a pure \t otherwise.
|
||||||
|
* [ ] And backspace which undents if before any content.
|
||||||
|
* [ ] Add block indentation support.
|
||||||
|
* [ ] Ignore comments/strings from parser when auto-indenting.
|
||||||
|
* [ ] These will dedent when the block immediately after them is dedented
|
||||||
|
* [ ] Dont dedent if ending is valid starting is invalid but also empty
|
||||||
|
* [ ] Just leave asis if starting is empty
|
||||||
|
* [ ] **Readme:** Update readme to show ruby based config.
|
||||||
|
* [ ] **UI Refinement:**
|
||||||
|
* [ ] Allow completion list to be scrolled; show only `x` max items.
|
||||||
|
* [ ] Finish autocomplete box style functions.
|
||||||
|
* [ ] **Documentation UI:** Capture `Ctrl+h` / `Ctrl+l` for scrolling documentation windows.
|
||||||
|
* [ ] Redo hooks as a struct.
|
||||||
|
* [ ] breakdown the render function into smaller functions.
|
||||||
|
|
||||||
|
* Try to make all functions better now that folds have been purged
|
||||||
|
* Cleanup syntax and renderer files
|
||||||
|
|
||||||
|
* Add a thing called view which is a rect with speacial type editor . but otherwise a ruby or c++ view
|
||||||
|
* can be used for stuff like file manager/git manager/theme picker.
|
||||||
|
* allow flushing functions in ruby to tell c++ to refresh keybinds/themes etc.
|
||||||
|
* allow keybinds to be set in ruby
|
||||||
|
|
||||||
|
check::
|
||||||
|
pull diagnostics for ruby-lsp
|
||||||
|
lsp selection range - use to highlight start / end of range maybe?
|
||||||
|
goto definiton
|
||||||
|
signature help
|
||||||
|
document symbol for the top bar maybe? (or workspace symbol)
|
||||||
|
also setup workspaces
|
||||||
|
Semantic highlighting
|
||||||
|
Quick fixes
|
||||||
|
Rename symbols
|
||||||
|
|
||||||
|
probably remove solargraph support and use ruby-lsp (or sorbet?) instead because it is a pain for utf stuff
|
||||||
|
ruby-lsp also supports erb so thats a plus
|
||||||
|
|
||||||
|
move lsp configs to json and also allow configs for windows-style vs unix-style line endings and utf-8 vs utf-16
|
||||||
|
|
||||||
|
* the ruby should have an api to be able to draw windows and add mappings to them
|
||||||
|
|
||||||
|
* finish bash then do all the directive-like ones like jsonc (first to help with theme files) / toml / yaml / ini / nginx
|
||||||
|
* then markdown / html
|
||||||
|
* then gitignore / gitattributes
|
||||||
|
* then fish then sql then css and [jt]sx? then python then lua (make with type annotations for lsp results)
|
||||||
|
* then [ch](++)? then gdscript then erb then php
|
||||||
|
* then haskell then gomod then go then rust
|
||||||
|
|
||||||
|
* [ ] **Undo/Redo:** Add support for undo/redo history.
|
||||||
|
|
||||||
|
* [ ] **Auto brace selection:** Add support for auto brace selection.
|
||||||
|
|
||||||
|
* [ ] **Tree-sitter Indent:** Attempt to allow Tree-sitter to handle indentation if possible.
|
||||||
|
|
||||||
|
* [ ] **Scrolling:** Add logic where selecting at the end of the screen scrolls down (and vice versa).
|
||||||
|
* *Implementation:* Update `main.cc` to send drag events to the selected editor even if coordinates are out of bounds.
|
||||||
|
|
||||||
|
|
||||||
|
### UX
|
||||||
|
|
||||||
|
* [ ] **Editor word highlighter:** Do not recompute word under cursor if not changed.
|
||||||
|
|
||||||
|
* [ ] **Completion Filtering:**
|
||||||
|
* [ ] Stop filtering case-sensitive.
|
||||||
|
* [ ] Normalize completion edits if local filtering is used.
|
||||||
|
|
||||||
|
* [ ] **LSP Features:**
|
||||||
|
* [ ] Add LSP jumping support (Go to Definition, Hover).
|
||||||
|
* [ ] Add LSP rename support.
|
||||||
|
* [ ] Handle snippets properly in autocomplete: use only the last word in signature when replacing and set cursor to the first one.
|
||||||
|
|
||||||
|
* [ ] **Basic Autocomplete:** Keep a list of words in the current buffer for non-LSP fallback.
|
||||||
|
|
||||||
|
### Major Features
|
||||||
|
|
||||||
|
* [ ] **Search & Replace:**
|
||||||
|
* [ ] Add Search/Replace UI.
|
||||||
|
* [ ] Support capture groups (`$1`, `$2`) or allow Perl regex directly.
|
||||||
|
* [ ] Ensure virtual cursors are included in search positions.
|
||||||
|
|
||||||
|
* [ ] **Multi-Cursor:**
|
||||||
|
* [ ] Add virtual cursor support (edits apply to all locations).
|
||||||
|
* [ ] Add `Alt+Click` to set multiple cursors.
|
||||||
|
* [ ] Allow search and place cursor at all matches.
|
||||||
|
|
||||||
|
* [ ] **Block Selection:**
|
||||||
|
* [ ] Double-clicking a bracket selects the whole block (first time only) and sets mode to `WORD`.
|
||||||
|
|
||||||
|
|
||||||
|
### Visuals, UI & Extensions?
|
||||||
|
|
||||||
|
* [ ] **Status Bar:** Complete status bar and command runner.
|
||||||
|
|
||||||
|
* [ ] Add color picker/palette.
|
||||||
|
|
||||||
|
* [ ] **Git:** Add Git integration (status, diffs).
|
||||||
|
* [ ] **AI/Snippets:**
|
||||||
|
* [ ] Add snippets support (LuaSnip/VSnip style).
|
||||||
|
* [ ] Add Codeium/Copilot support (using VAI virtual text) as a test phase.
|
||||||
|
|
||||||
|
* [ ] **SQL:** Add SQL support (Viewer and Basic Editor).
|
||||||
|
* [ ] **Prolly?:** Add Splash Screen / Minigame.
|
||||||
|
|
||||||
|
|
||||||
|
### Optimizations & Fluff
|
||||||
|
|
||||||
|
* [ ] **Performance:**
|
||||||
|
* [ ] Switch JSON parser to `RapidJSON` (or similar high-performance lib).
|
||||||
|
* [ ] Decrease usage of `std::string` in UI, LSP, and warnings.
|
||||||
|
* [ ] Also for vectors into managed memory especially for completions/lsp-stuff.
|
||||||
|
|
||||||
128
config/main.rb
Normal file
128
config/main.rb
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
# basic configuration
|
||||||
|
# This can also be used to do speacail configs for different projects.
|
||||||
|
# its ruby guys script whatever you want.
|
||||||
|
|
||||||
|
# puts "Loading main config..."
|
||||||
|
|
||||||
|
C.startup do
|
||||||
|
puts "Starting crib..."
|
||||||
|
end
|
||||||
|
|
||||||
|
C.shutdown do
|
||||||
|
puts "Exiting crib..."
|
||||||
|
end
|
||||||
|
|
||||||
|
# this can be modified by the user during runtime through keybindings
|
||||||
|
# But i need to know how to ever read this value only when needed.
|
||||||
|
# maybe i can write a function that notifies if theme maybe changed then reload
|
||||||
|
# It can also be scripted to load different theme formats into a hash usable by crib
|
||||||
|
C.theme = {
|
||||||
|
:default => { fg: 0xEEEEEE },
|
||||||
|
:shebang => { fg: 0x7DCFFF },
|
||||||
|
:error => { fg: 0xEF5168 },
|
||||||
|
:comment => { fg: 0xAAAAAA, italic: true },
|
||||||
|
:string => { fg: 0xAAD94C },
|
||||||
|
:escape => { fg: 0x7DCFFF },
|
||||||
|
:interpolation => { fg: 0x7DCFFF },
|
||||||
|
:regexp => { fg: 0xD2A6FF },
|
||||||
|
:number => { fg: 0xE6C08A },
|
||||||
|
# rubocop:disable Lint/BooleanSymbol
|
||||||
|
:true => { fg: 0x7AE93C },
|
||||||
|
:false => { fg: 0xEF5168 },
|
||||||
|
# rubocop:enable Lint/BooleanSymbol
|
||||||
|
:char => { fg: 0xFFAF70 },
|
||||||
|
:keyword => { fg: 0xFF8F40 },
|
||||||
|
:keywordoperator => { fg: 0xF07178 },
|
||||||
|
:operator => { fg: 0xFFFFFF, italic: true },
|
||||||
|
:function => { fg: 0xFFAF70 },
|
||||||
|
:type => { fg: 0xF07178 },
|
||||||
|
:constant => { fg: 0x7DCFFF },
|
||||||
|
:variableinstance => { fg: 0x95E6CB },
|
||||||
|
:variableglobal => { fg: 0xF07178 },
|
||||||
|
:annotation => { fg: 0x7DCFFF },
|
||||||
|
:directive => { fg: 0xFF8F40 },
|
||||||
|
:label => { fg: 0xD2A6FF },
|
||||||
|
:brace1 => { fg: 0xD2A6FF },
|
||||||
|
:brace2 => { fg: 0xFFAFAF },
|
||||||
|
:brace3 => { fg: 0xFFFF00 },
|
||||||
|
:brace4 => { fg: 0x0FFF0F },
|
||||||
|
:brace5 => { fg: 0xFF0F0F }
|
||||||
|
}
|
||||||
|
|
||||||
|
# TODO: to be done once a proper api for binding and window drawing is made
|
||||||
|
# The binds will be connected to either `editor` or windows where editor can
|
||||||
|
# only use a preset set of stuff to bind while teh windows are purely custom
|
||||||
|
# # this part uses dsl bindings to define the bind function
|
||||||
|
# # Hopefully extend to give more context/power to bindings
|
||||||
|
# # but try to keep simple for performance
|
||||||
|
# # for default keybindings
|
||||||
|
# C.bind [:normal, :select], :a => "insert_mode"
|
||||||
|
# # for custom keybindings
|
||||||
|
# C.bind :select, [:x, :c] do
|
||||||
|
# puts "cut"
|
||||||
|
# end
|
||||||
|
# C.bind :jumper do
|
||||||
|
# set [:x, :c] do
|
||||||
|
# puts "jump to first bookmark"
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# # they can also be defined conditionally
|
||||||
|
# # This code is just an example and doesnt actually work
|
||||||
|
# if using_tmux?
|
||||||
|
# bind :C-p do
|
||||||
|
# system("tmux select-pane -U")
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
# This can, for example, be modified by user bindings during runtime
|
||||||
|
# TODO: dynamic registration to actually be implemented once keybinds and extentions are implemented
|
||||||
|
# A predefined list already exists and can be found in libcrib.rb
|
||||||
|
# C.lsp_config["solargraph"] = ["stdio"]
|
||||||
|
#
|
||||||
|
# C.languages[:ruby] = {
|
||||||
|
# color: 0xff8087,
|
||||||
|
# symbol: " ",
|
||||||
|
# extensions: ["rb"],
|
||||||
|
# filenames: ["Gemfile"],
|
||||||
|
# lsp: "solargraph"
|
||||||
|
# }
|
||||||
|
|
||||||
|
C.line_endings = :auto_unix # or :unix or :windows or :auto_windows
|
||||||
|
|
||||||
|
C.extra_highlights do |_line, _idx|
|
||||||
|
# the return can be an array of
|
||||||
|
# [fg, bg. flags, start, end]
|
||||||
|
# where fg and bg are integers (using 24 bit color)
|
||||||
|
# and flags is a bitmask of bold/underline/italic etc
|
||||||
|
# and start and end are integers strictly inside the line
|
||||||
|
return []
|
||||||
|
end
|
||||||
|
|
||||||
|
# The highlighter will be aplied to the language as long as the langauge is defined in C.languages
|
||||||
|
C.highlighters[:ruby_n] = {
|
||||||
|
parser: ->(line, state, line_idx) {
|
||||||
|
# the return value is a hash
|
||||||
|
# it contains the state and the highlights
|
||||||
|
# state can be of any type but will be consistent between calls
|
||||||
|
# initially nil is sent for uninitialized state the returned must be anything but nil
|
||||||
|
# the same state can be used for multiple lines
|
||||||
|
# the highlights can be an array of
|
||||||
|
# [K_type, start, end]
|
||||||
|
# K_type is a constant from the constants defined in libcrib.rb
|
||||||
|
# for ex: for strings it would be Tokens::K_STRING or for numbers Tokens::K_NUMBER etc.
|
||||||
|
# and start and end are integers strictly inside the line
|
||||||
|
return {
|
||||||
|
state: "",
|
||||||
|
tokens: [
|
||||||
|
# This will highlight the entire line as a string
|
||||||
|
# Any wrong format will not be handled and lead to crashes
|
||||||
|
{ type: Tokens::K_STRING, start: 0, end: line.length }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
matcher: ->(state1, state2) {
|
||||||
|
# returns true if the states are equal
|
||||||
|
# And so would not need recomputation for further lines
|
||||||
|
return state1 == state2
|
||||||
|
}
|
||||||
|
}
|
||||||
288
grammar/bash.scm
288
grammar/bash.scm
@@ -1,288 +0,0 @@
|
|||||||
[
|
|
||||||
(function_definition)
|
|
||||||
(if_statement)
|
|
||||||
(case_statement)
|
|
||||||
(for_statement)
|
|
||||||
(while_statement)
|
|
||||||
(c_style_for_statement)
|
|
||||||
(heredoc_redirect)
|
|
||||||
] @fold
|
|
||||||
|
|
||||||
;; #bd9ae6 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"("
|
|
||||||
")"
|
|
||||||
"{"
|
|
||||||
"}"
|
|
||||||
"["
|
|
||||||
"]"
|
|
||||||
"[["
|
|
||||||
"]]"
|
|
||||||
"(("
|
|
||||||
"))"
|
|
||||||
] @punctuation.bracket
|
|
||||||
|
|
||||||
;; #bd9ae6 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
";"
|
|
||||||
";;"
|
|
||||||
";&"
|
|
||||||
";;&"
|
|
||||||
"&"
|
|
||||||
] @punctuation.delimiter
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 1 0 1
|
|
||||||
[
|
|
||||||
">"
|
|
||||||
">>"
|
|
||||||
"<"
|
|
||||||
"<<"
|
|
||||||
"&&"
|
|
||||||
"|"
|
|
||||||
"|&"
|
|
||||||
"||"
|
|
||||||
"="
|
|
||||||
"+="
|
|
||||||
"=~"
|
|
||||||
"=="
|
|
||||||
"!="
|
|
||||||
"&>"
|
|
||||||
"&>>"
|
|
||||||
"<&"
|
|
||||||
">&"
|
|
||||||
">|"
|
|
||||||
"<&-"
|
|
||||||
">&-"
|
|
||||||
"<<-"
|
|
||||||
"<<<"
|
|
||||||
".."
|
|
||||||
"!"
|
|
||||||
] @operator
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
(string)
|
|
||||||
(raw_string)
|
|
||||||
(ansi_c_string)
|
|
||||||
(heredoc_body)
|
|
||||||
] @string
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
(heredoc_start)
|
|
||||||
(heredoc_end)
|
|
||||||
] @label
|
|
||||||
|
|
||||||
(variable_assignment
|
|
||||||
(word) @string)
|
|
||||||
|
|
||||||
(command
|
|
||||||
argument: "$" @string) ; bare dollar
|
|
||||||
|
|
||||||
(concatenation
|
|
||||||
(word) @string)
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"if"
|
|
||||||
"then"
|
|
||||||
"else"
|
|
||||||
"elif"
|
|
||||||
"fi"
|
|
||||||
"case"
|
|
||||||
"in"
|
|
||||||
"esac"
|
|
||||||
] @keyword.conditional
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"for"
|
|
||||||
"do"
|
|
||||||
"done"
|
|
||||||
"select"
|
|
||||||
"until"
|
|
||||||
"while"
|
|
||||||
] @keyword.repeat
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"declare"
|
|
||||||
"typeset"
|
|
||||||
"readonly"
|
|
||||||
"local"
|
|
||||||
"unset"
|
|
||||||
"unsetenv"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
"export" @keyword.import
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
"function" @keyword.function
|
|
||||||
|
|
||||||
;; #ebda8c #000000 0 0 0 1
|
|
||||||
(special_variable_name) @constant
|
|
||||||
|
|
||||||
;; #ebda8c #000000 0 0 0 1
|
|
||||||
((word) @constant.builtin
|
|
||||||
(#match? @constant.builtin "^(SIGHUP|SIGINT|SIGQUIT|SIGILL|SIGTRAP|SIGABRT|SIGBUS|SIGFPE|SIGKILL|SIGUSR1|SIGSEGV|SIGUSR2|SIGPIPE|SIGALRM|SIGTERM|SIGSTKFLT|SIGCHLD|SIGCONT|SIGSTOP|SIGTSTP|SIGTTIN|SIGTTOU|SIGURG|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGIO|SIGPWR|SIGSYS|SIGRTMIN|SIGRTMIN\+1|SIGRTMIN\+2|SIGRTMIN\+3|SIGRTMIN\+4|SIGRTMIN\+5|SIGRTMIN\+6|SIGRTMIN\+7|SIGRTMIN\+8|SIGRTMIN\+9|SIGRTMIN\+10|SIGRTMIN\+11|SIGRTMIN\+12|SIGRTMIN\+13|SIGRTMIN\+14|SIGRTMIN\+15|SIGRTMAX\-14|SIGRTMAX\-13|SIGRTMAX\-12|SIGRTMAX\-11|SIGRTMAX\-10|SIGRTMAX\-9|SIGRTMAX\-8|SIGRTMAX\-7|SIGRTMAX\-6|SIGRTMAX\-5|SIGRTMAX\-4|SIGRTMAX\-3|SIGRTMAX\-2|SIGRTMAX\-1|SIGRTMAX)$"))
|
|
||||||
|
|
||||||
;; #51eeba #000000 0 0 0 1
|
|
||||||
((word) @boolean.true
|
|
||||||
(#match? @boolean.true "^true$"))
|
|
||||||
|
|
||||||
;; #ee513a #000000 0 0 0 1
|
|
||||||
((word) @boolean.false
|
|
||||||
(#match? @boolean.false "^false$"))
|
|
||||||
|
|
||||||
;; #AAAAAA #000000 0 1 0 1
|
|
||||||
(comment) @comment @spell
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(test_operator) @operator
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(command_substitution
|
|
||||||
"$(" @punctuation.special
|
|
||||||
")" @punctuation.special)
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(process_substitution
|
|
||||||
[
|
|
||||||
"<("
|
|
||||||
">("
|
|
||||||
] @punctuation.special
|
|
||||||
")" @punctuation.special)
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(arithmetic_expansion
|
|
||||||
[
|
|
||||||
"$(("
|
|
||||||
"(("
|
|
||||||
] @punctuation.special
|
|
||||||
"))" @punctuation.special)
|
|
||||||
|
|
||||||
;; #bd9ae6 #000000 0 0 0 1
|
|
||||||
(arithmetic_expansion
|
|
||||||
"," @punctuation.delimiter)
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(ternary_expression
|
|
||||||
[
|
|
||||||
"?"
|
|
||||||
":"
|
|
||||||
] @keyword.conditional.ternary)
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(binary_expression
|
|
||||||
operator: _ @operator)
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(unary_expression
|
|
||||||
operator: _ @operator)
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(postfix_expression
|
|
||||||
operator: _ @operator)
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 3
|
|
||||||
(function_definition
|
|
||||||
name: (word) @function)
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 3
|
|
||||||
(command_name
|
|
||||||
(word) @function.call)
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 3
|
|
||||||
(command_name
|
|
||||||
(word) @function.builtin
|
|
||||||
(#match? @function.builtin "^(\.|\:|alias|bg|bind|break|builtin|caller|cd|command|compgen|complete|compopt|continue|coproc|dirs|disown|echo|enable|eval|exec|exit|false|fc|fg|getopts|hash|help|history|jobs|kill|let|logout|mapfile|popd|printf|pushd|pwd|read|readarray|return|set|shift|shopt|source|suspend|test|time|times|trap|true|type|typeset|ulimit|umask|unalias|wait)$"))
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(command
|
|
||||||
argument: [
|
|
||||||
(word) @variable.parameter
|
|
||||||
(concatenation
|
|
||||||
(word) @variable.parameter)
|
|
||||||
])
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(declaration_command
|
|
||||||
(word) @variable.parameter)
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(unset_command
|
|
||||||
(word) @variable.parameter)
|
|
||||||
|
|
||||||
;; #ebda8c #000000 0 0 0 2
|
|
||||||
(number) @number
|
|
||||||
|
|
||||||
;; #ebda8c #000000 0 0 0 2
|
|
||||||
((word) @number
|
|
||||||
(#match? @number "^[0-9]+$"))
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 1
|
|
||||||
(file_redirect
|
|
||||||
(word) @string.special.path)
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 1
|
|
||||||
(herestring_redirect
|
|
||||||
(word) @string)
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(file_descriptor) @operator
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(simple_expansion
|
|
||||||
"$" @punctuation.special) @none
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(expansion
|
|
||||||
"${" @punctuation.special
|
|
||||||
"}" @punctuation.special) @none
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(expansion
|
|
||||||
operator: _ @punctuation.special)
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(expansion
|
|
||||||
"@"
|
|
||||||
.
|
|
||||||
operator: _ @character.special)
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
((expansion
|
|
||||||
(subscript
|
|
||||||
index: (word) @character.special))
|
|
||||||
(#any-of? @character.special "@" "*"))
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
"``" @punctuation.special
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(variable_name) @variable
|
|
||||||
|
|
||||||
;; #ebda8c #000000 0 0 0 1
|
|
||||||
((variable_name) @constant
|
|
||||||
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
((variable_name) @variable.builtin
|
|
||||||
(#match? @variable.builtin "^(CDPATH|HOME|IFS|MAIL|MAILPATH|OPTARG|OPTIND|PATH|PS1|PS2|_|BASH|BASHOPTS|BASHPID|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_ARGV0|BASH_CMDS|BASH_COMMAND|BASH_COMPAT|BASH_ENV|BASH_EXECUTION_STRING|BASH_LINENO|BASH_LOADABLES_PATH|BASH_REMATCH|BASH_SOURCE|BASH_SUBSHELL|BASH_VERSINFO|BASH_VERSION|BASH_XTRACEFD|CHILD_MAX|COLUMNS|COMP_CWORD|COMP_LINE|COMP_POINT|COMP_TYPE|COMP_KEY|COMP_WORDBREAKS|COMP_WORDS|COMPREPLY|COPROC|DIRSTACK|EMACS|ENV|EPOCHREALTIME|EPOCHSECONDS|EUID|EXECIGNORE|FCEDIT|FIGNORE|FUNCNAME|FUNCNEST|GLOBIGNORE|GROUPS|histchars|HISTCMD|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTIGNORE|HISTSIZE|HISTTIMEFORMAT|HOSTFILE|HOSTNAME|HOSTTYPE|IGNOREEOF|INPUTRC|INSIDE_EMACS|LANG|LC_ALL|LC_COLLATE|LC_CTYPE|LC_MESSAGES|LC_NUMERIC|LC_TIME|LINENO|LINES|MACHTYPE|MAILCHECK|MAPFILE|OLDPWD|OPTERR|OSTYPE|PIPESTATUS|POSIXLY_CORRECT|PPID|PROMPT_COMMAND|PROMPT_DIRTRIM|PS0|PS3|PS4|PWD|RANDOM|READLINE_ARGUMENT|READLINE_LINE|READLINE_MARK|READLINE_POINT|REPLY|SECONDS|SHELL|SHELLOPTS|SHLVL|SRANDOM|TIMEFORMAT|TMOUT|TMPDIR|UID)$"))
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(case_item
|
|
||||||
value: (word) @variable.parameter)
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
[
|
|
||||||
(regex)
|
|
||||||
(extglob_pattern)
|
|
||||||
] @string.regexp
|
|
||||||
|
|
||||||
;; #51eeba #000000 0 0 0 3
|
|
||||||
((program
|
|
||||||
.
|
|
||||||
(comment) @keyword.directive @nospell)
|
|
||||||
(#match? @keyword.directive "^#!/"))
|
|
||||||
333
grammar/ruby.scm
333
grammar/ruby.scm
@@ -1,333 +0,0 @@
|
|||||||
[
|
|
||||||
(method)
|
|
||||||
(singleton_method)
|
|
||||||
(class)
|
|
||||||
(module)
|
|
||||||
(if)
|
|
||||||
(else)
|
|
||||||
(case)
|
|
||||||
(when)
|
|
||||||
(in)
|
|
||||||
(do_block)
|
|
||||||
(singleton_class)
|
|
||||||
(heredoc_content)
|
|
||||||
(lambda)
|
|
||||||
] @fold
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
(identifier)
|
|
||||||
(global_variable)
|
|
||||||
] @variable
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"alias"
|
|
||||||
"begin"
|
|
||||||
"do"
|
|
||||||
"end"
|
|
||||||
"ensure"
|
|
||||||
"module"
|
|
||||||
"rescue"
|
|
||||||
"then"
|
|
||||||
] @keyword
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
"class" @keyword.type
|
|
||||||
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"return"
|
|
||||||
"yield"
|
|
||||||
] @keyword.return
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"and"
|
|
||||||
"or"
|
|
||||||
"in"
|
|
||||||
"not"
|
|
||||||
] @keyword.operator
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"def"
|
|
||||||
"undef"
|
|
||||||
] @keyword.function
|
|
||||||
|
|
||||||
(method
|
|
||||||
"end" @keyword.function)
|
|
||||||
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"case"
|
|
||||||
"else"
|
|
||||||
"elsif"
|
|
||||||
"if"
|
|
||||||
"unless"
|
|
||||||
"when"
|
|
||||||
"then"
|
|
||||||
] @keyword.conditional
|
|
||||||
|
|
||||||
(if
|
|
||||||
"end" @keyword.conditional)
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"for"
|
|
||||||
"until"
|
|
||||||
"while"
|
|
||||||
"break"
|
|
||||||
"redo"
|
|
||||||
"retry"
|
|
||||||
"next"
|
|
||||||
] @keyword.repeat
|
|
||||||
|
|
||||||
;; #ebda8c #000000 0 0 0 1
|
|
||||||
(constant) @constant
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"rescue"
|
|
||||||
"ensure"
|
|
||||||
] @keyword.exception
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 1
|
|
||||||
"defined?" @function
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 3
|
|
||||||
(call
|
|
||||||
receiver: (constant)? @type
|
|
||||||
method: [
|
|
||||||
(identifier)
|
|
||||||
(constant)
|
|
||||||
;; #ff5689 #000000 0 0 0 2
|
|
||||||
] @function.call)
|
|
||||||
|
|
||||||
(alias
|
|
||||||
(identifier) @function)
|
|
||||||
|
|
||||||
(setter
|
|
||||||
(identifier) @function)
|
|
||||||
|
|
||||||
(method
|
|
||||||
name: [
|
|
||||||
(identifier) @function
|
|
||||||
(constant) @type
|
|
||||||
])
|
|
||||||
|
|
||||||
(singleton_method
|
|
||||||
name: [
|
|
||||||
(identifier) @function
|
|
||||||
(constant) @type
|
|
||||||
])
|
|
||||||
|
|
||||||
(class
|
|
||||||
name: (constant) @type)
|
|
||||||
|
|
||||||
(module
|
|
||||||
name: (constant) @type)
|
|
||||||
|
|
||||||
(superclass
|
|
||||||
(constant) @type)
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
(class_variable)
|
|
||||||
(instance_variable)
|
|
||||||
] @variable.member
|
|
||||||
|
|
||||||
((identifier) @keyword.modifier
|
|
||||||
(#match? @keyword.modifier "^(private|protected|public)$" ))
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 3
|
|
||||||
(program
|
|
||||||
(call
|
|
||||||
(identifier) @keyword.import)
|
|
||||||
(#match? @keyword.import "^(require|require_relative|load)$"))
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 4
|
|
||||||
((identifier) @constant.builtin
|
|
||||||
(#match? @constant.builtin "^(__callee__|__dir__|__id__|__method__|__send__|__ENCODING__|__FILE__|__LINE__)$" ))
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 3
|
|
||||||
((identifier) @function.builtin
|
|
||||||
(#match? @function.builtin "^(attr_reader|attr_writer|attr_accessor|module_function)$" ))
|
|
||||||
|
|
||||||
((call
|
|
||||||
!receiver
|
|
||||||
method: (identifier) @function.builtin)
|
|
||||||
(#match? @function.builtin "^(include|extend|prepend|refine|using)"))
|
|
||||||
|
|
||||||
((identifier) @keyword.exception
|
|
||||||
(#match? @keyword.exception "^(raise|fail|catch|throw)" ))
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
(self)
|
|
||||||
(super)
|
|
||||||
] @variable.builtin
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
(method_parameters
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
(lambda_parameters
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
(block_parameters
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
(splat_parameter
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
(hash_splat_parameter
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
(optional_parameter
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
(destructured_parameter
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
(block_parameter
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
(keyword_parameter
|
|
||||||
(identifier) @variable.parameter)
|
|
||||||
|
|
||||||
;; #aad84c #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
(string_content)
|
|
||||||
(heredoc_content)
|
|
||||||
"\""
|
|
||||||
"`"
|
|
||||||
] @string
|
|
||||||
|
|
||||||
;; #fbb152 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
(heredoc_beginning)
|
|
||||||
(heredoc_end)
|
|
||||||
] @label
|
|
||||||
|
|
||||||
;; #bd9ae6 #000000 0 0 0 2
|
|
||||||
[
|
|
||||||
(bare_symbol)
|
|
||||||
(simple_symbol)
|
|
||||||
(delimited_symbol)
|
|
||||||
(hash_key_symbol)
|
|
||||||
] @string.special.symbol
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(regex
|
|
||||||
(string_content) @string.regexp)
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(escape_sequence) @string.escape
|
|
||||||
|
|
||||||
;; #ebda8c #000000 0 0 0 2
|
|
||||||
(integer) @number
|
|
||||||
|
|
||||||
;; #ebda8c #000000 0 0 0 2
|
|
||||||
(float) @number.float
|
|
||||||
|
|
||||||
;; #51eeba #000000 0 0 0 1
|
|
||||||
(true) @boolean.true
|
|
||||||
|
|
||||||
;; #ee513a #000000 0 0 0 1
|
|
||||||
(false) @boolean.false
|
|
||||||
|
|
||||||
;; #ee8757 #000000 0 0 0 1
|
|
||||||
(nil) @constant.nil
|
|
||||||
|
|
||||||
;; #AAAAAA #000000 0 1 0 1
|
|
||||||
(comment) @comment
|
|
||||||
|
|
||||||
;; #51eeba #000000 0 0 0 3
|
|
||||||
((program
|
|
||||||
.
|
|
||||||
(comment) @shebang @nospell)
|
|
||||||
(#match? @shebang "^#!/"))
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"!"
|
|
||||||
"="
|
|
||||||
">>"
|
|
||||||
"<<"
|
|
||||||
">"
|
|
||||||
"<"
|
|
||||||
"**"
|
|
||||||
"*"
|
|
||||||
"/"
|
|
||||||
"%"
|
|
||||||
"+"
|
|
||||||
"-"
|
|
||||||
"&"
|
|
||||||
"|"
|
|
||||||
"^"
|
|
||||||
"%="
|
|
||||||
"+="
|
|
||||||
"-="
|
|
||||||
"*="
|
|
||||||
"/="
|
|
||||||
"=~"
|
|
||||||
"!~"
|
|
||||||
"?"
|
|
||||||
":"
|
|
||||||
] @operator
|
|
||||||
|
|
||||||
;; #ffffff #000000 0 1 0 1
|
|
||||||
[
|
|
||||||
"=="
|
|
||||||
"==="
|
|
||||||
"<=>"
|
|
||||||
"=>"
|
|
||||||
"->"
|
|
||||||
">="
|
|
||||||
"<="
|
|
||||||
"||"
|
|
||||||
"||="
|
|
||||||
"&&="
|
|
||||||
"&&"
|
|
||||||
"!="
|
|
||||||
".."
|
|
||||||
"..."
|
|
||||||
] @operator.ligature
|
|
||||||
|
|
||||||
;; #bd9ae6 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
","
|
|
||||||
";"
|
|
||||||
"."
|
|
||||||
"&."
|
|
||||||
"::"
|
|
||||||
] @punctuation.delimiter
|
|
||||||
|
|
||||||
(pair
|
|
||||||
":" @punctuation.delimiter)
|
|
||||||
|
|
||||||
;; #bd9ae6 #000000 0 0 0 1
|
|
||||||
[
|
|
||||||
"("
|
|
||||||
")"
|
|
||||||
"["
|
|
||||||
"]"
|
|
||||||
"{"
|
|
||||||
"}"
|
|
||||||
"%w("
|
|
||||||
"%i("
|
|
||||||
] @punctuation.bracket
|
|
||||||
|
|
||||||
(regex
|
|
||||||
"/" @punctuation.bracket)
|
|
||||||
|
|
||||||
(block_parameters
|
|
||||||
"|" @punctuation.bracket)
|
|
||||||
|
|
||||||
;; #e6a24c #000000 0 0 0 2
|
|
||||||
(interpolation
|
|
||||||
"#{" @punctuation.special
|
|
||||||
"}" @punctuation.special)
|
|
||||||
119
include/editor.h
119
include/editor.h
@@ -1,119 +0,0 @@
|
|||||||
#ifndef EDITOR_H
|
|
||||||
#define EDITOR_H
|
|
||||||
|
|
||||||
#include "../libs/tree-sitter/lib/include/tree_sitter/api.h"
|
|
||||||
#include "./knot.h"
|
|
||||||
#include "./ui.h"
|
|
||||||
#include "./utils.h"
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <map>
|
|
||||||
#include <shared_mutex>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
struct Highlight {
|
|
||||||
uint32_t fg;
|
|
||||||
uint32_t bg;
|
|
||||||
uint32_t flags;
|
|
||||||
uint8_t priority;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Span {
|
|
||||||
uint32_t start;
|
|
||||||
uint32_t end;
|
|
||||||
Highlight *hl;
|
|
||||||
|
|
||||||
bool operator<(const Span &other) const { return start < other.start; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Spans {
|
|
||||||
std::vector<Span> spans;
|
|
||||||
Queue<std::pair<uint32_t, int64_t>> edits;
|
|
||||||
bool mid_parse = false;
|
|
||||||
std::shared_mutex mtx;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SpanCursor {
|
|
||||||
Spans &spans;
|
|
||||||
size_t index = 0;
|
|
||||||
std::vector<Span *> active;
|
|
||||||
std::shared_lock<std::shared_mutex> lock;
|
|
||||||
|
|
||||||
SpanCursor(Spans &s) : spans(s) {}
|
|
||||||
Highlight *get_highlight(uint32_t byte_offset) {
|
|
||||||
for (int i = (int)active.size() - 1; i >= 0; i--)
|
|
||||||
if (active[i]->end <= byte_offset)
|
|
||||||
active.erase(active.begin() + i);
|
|
||||||
while (index < spans.spans.size() &&
|
|
||||||
spans.spans[index].start <= byte_offset) {
|
|
||||||
if (spans.spans[index].end > byte_offset)
|
|
||||||
active.push_back(const_cast<Span *>(&spans.spans[index]));
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
Highlight *best = nullptr;
|
|
||||||
int max_prio = -1;
|
|
||||||
for (auto *s : active)
|
|
||||||
if (s->hl->priority > max_prio) {
|
|
||||||
max_prio = s->hl->priority;
|
|
||||||
best = s->hl;
|
|
||||||
}
|
|
||||||
return best;
|
|
||||||
}
|
|
||||||
void sync(uint32_t byte_offset) {
|
|
||||||
lock = std::shared_lock(spans.mtx);
|
|
||||||
active.clear();
|
|
||||||
size_t left = 0, right = spans.spans.size();
|
|
||||||
while (left < right) {
|
|
||||||
size_t mid = (left + right) / 2;
|
|
||||||
if (spans.spans[mid].start <= byte_offset)
|
|
||||||
left = mid + 1;
|
|
||||||
else
|
|
||||||
right = mid;
|
|
||||||
}
|
|
||||||
index = left;
|
|
||||||
while (left > 0) {
|
|
||||||
left--;
|
|
||||||
if (spans.spans[left].end > byte_offset)
|
|
||||||
active.push_back(const_cast<Span *>(&spans.spans[left]));
|
|
||||||
else if (byte_offset - spans.spans[left].end > 1000)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Editor {
|
|
||||||
const char *filename;
|
|
||||||
Knot *root;
|
|
||||||
std::shared_mutex knot_mtx;
|
|
||||||
Coord cursor;
|
|
||||||
uint32_t cursor_preffered;
|
|
||||||
Coord selection;
|
|
||||||
bool selection_active;
|
|
||||||
Coord position;
|
|
||||||
Coord size;
|
|
||||||
Coord scroll;
|
|
||||||
TSTree *tree;
|
|
||||||
TSParser *parser;
|
|
||||||
TSQuery *query;
|
|
||||||
const TSLanguage *language;
|
|
||||||
Queue<TSInputEdit> edit_queue;
|
|
||||||
std::vector<Highlight> query_map;
|
|
||||||
std::vector<int8_t> folded;
|
|
||||||
Spans spans;
|
|
||||||
std::map<uint32_t, bool> folded_node;
|
|
||||||
};
|
|
||||||
|
|
||||||
Editor *new_editor(const char *filename, Coord position, Coord size);
|
|
||||||
void free_editor(Editor *editor);
|
|
||||||
void render_editor(Editor *editor);
|
|
||||||
void fold(Editor *editor, uint32_t start_line, uint32_t end_line);
|
|
||||||
void scroll_up(Editor *editor, uint32_t lines);
|
|
||||||
void scroll_down(Editor *editor, uint32_t lines);
|
|
||||||
void cursor_up(Editor *editor, uint32_t number);
|
|
||||||
void cursor_down(Editor *editor, uint32_t number);
|
|
||||||
void cursor_left(Editor *editor, uint32_t number);
|
|
||||||
void cursor_right(Editor *editor, uint32_t number);
|
|
||||||
void ensure_scroll(Editor *editor);
|
|
||||||
void apply_edit(std::vector<Span> &spans, uint32_t x, int64_t y);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
46
include/editor/completions.h
Normal file
46
include/editor/completions.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#ifndef EDITOR_COMPLETIONS_H
|
||||||
|
#define EDITOR_COMPLETIONS_H
|
||||||
|
|
||||||
|
#include "pch.h"
|
||||||
|
#include "ui/completionbox.h"
|
||||||
|
#include "ui/hover.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
struct CompletionItem {
|
||||||
|
std::string label;
|
||||||
|
uint8_t kind;
|
||||||
|
std::optional<std::string> detail;
|
||||||
|
std::optional<std::string> documentation;
|
||||||
|
bool is_markup = false;
|
||||||
|
bool deprecated = false;
|
||||||
|
bool asis = true;
|
||||||
|
std::string sort;
|
||||||
|
std::string filter;
|
||||||
|
bool snippet = false;
|
||||||
|
std::vector<TextEdit> edits;
|
||||||
|
json original;
|
||||||
|
std::vector<char> end_chars;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CompletionSession {
|
||||||
|
std::shared_mutex mtx;
|
||||||
|
bool active = false;
|
||||||
|
Coord hook;
|
||||||
|
std::optional<std::string> prefix;
|
||||||
|
uint32_t select = 0;
|
||||||
|
uint32_t scroll = 0;
|
||||||
|
std::vector<CompletionItem> items;
|
||||||
|
std::vector<uint32_t> visible;
|
||||||
|
bool complete = true;
|
||||||
|
std::optional<char> trigger_char;
|
||||||
|
uint8_t trigger = 0;
|
||||||
|
CompletionBox box;
|
||||||
|
HoverBox hover;
|
||||||
|
uint32_t doc = UINT32_MAX;
|
||||||
|
std::atomic<bool> hover_dirty = false;
|
||||||
|
int version;
|
||||||
|
|
||||||
|
CompletionSession() : box(this) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
35
include/editor/decl.h
Normal file
35
include/editor/decl.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef EDITOR_DECL_H
|
||||||
|
#define EDITOR_DECL_H
|
||||||
|
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
struct TextEdit {
|
||||||
|
Coord start;
|
||||||
|
Coord end;
|
||||||
|
std::string text;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VWarn {
|
||||||
|
uint32_t line;
|
||||||
|
std::string text;
|
||||||
|
std::string text_full;
|
||||||
|
std::string source;
|
||||||
|
std::string code;
|
||||||
|
std::vector<std::string> see_also;
|
||||||
|
int8_t type;
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t end{UINT32_MAX};
|
||||||
|
|
||||||
|
bool operator<(const VWarn &other) const { return line < other.line; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VAI {
|
||||||
|
Coord pos;
|
||||||
|
char *text;
|
||||||
|
uint32_t len;
|
||||||
|
uint32_t lines; // number of \n in text for speed .. the ai part will not
|
||||||
|
// line wrap but multiline ones need to have its own lines
|
||||||
|
// after the first one
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
163
include/editor/editor.h
Normal file
163
include/editor/editor.h
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#ifndef EDITOR_H
|
||||||
|
#define EDITOR_H
|
||||||
|
|
||||||
|
#include "editor/completions.h"
|
||||||
|
#include "editor/indents.h"
|
||||||
|
#include "io/knot.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "syntax/extras.h"
|
||||||
|
#include "syntax/parser.h"
|
||||||
|
#include "ui/completionbox.h"
|
||||||
|
#include "ui/diagnostics.h"
|
||||||
|
#include "ui/hover.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#define CHAR 0
|
||||||
|
#define WORD 1
|
||||||
|
#define LINE 2
|
||||||
|
|
||||||
|
#define EXTRA_META 2
|
||||||
|
#define INDENT_WIDTH 2
|
||||||
|
|
||||||
|
struct Editor {
|
||||||
|
std::string filename;
|
||||||
|
std::string uri;
|
||||||
|
Knot *root;
|
||||||
|
std::shared_mutex knot_mtx;
|
||||||
|
Coord cursor;
|
||||||
|
uint32_t cursor_preffered;
|
||||||
|
Coord selection;
|
||||||
|
bool selection_active;
|
||||||
|
bool unix_eol;
|
||||||
|
int selection_type;
|
||||||
|
Coord position;
|
||||||
|
Coord size;
|
||||||
|
Coord scroll;
|
||||||
|
Language lang;
|
||||||
|
uint32_t hooks[94];
|
||||||
|
bool jumper_set;
|
||||||
|
std::shared_mutex v_mtx;
|
||||||
|
std::vector<VWarn> warnings;
|
||||||
|
bool warnings_dirty;
|
||||||
|
VAI ai;
|
||||||
|
std::shared_mutex lsp_mtx;
|
||||||
|
std::shared_ptr<struct LSPInstance> lsp;
|
||||||
|
bool hover_active;
|
||||||
|
HoverBox hover;
|
||||||
|
bool diagnostics_active;
|
||||||
|
DiagnosticBox diagnostics;
|
||||||
|
std::atomic<int> lsp_version = 1;
|
||||||
|
CompletionSession completion;
|
||||||
|
IndentationEngine indents;
|
||||||
|
Parser *parser;
|
||||||
|
ExtraHighlighter extra_hl;
|
||||||
|
bool is_css_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
Editor *new_editor(const char *filename_arg, Coord position, Coord size,
|
||||||
|
uint8_t eol);
|
||||||
|
void save_file(Editor *editor);
|
||||||
|
void free_editor(Editor *editor);
|
||||||
|
void render_editor(Editor *editor);
|
||||||
|
void cursor_up(Editor *editor, uint32_t number);
|
||||||
|
void cursor_down(Editor *editor, uint32_t number);
|
||||||
|
Coord move_left(Editor *editor, Coord cursor, uint32_t number);
|
||||||
|
Coord move_right(Editor *editor, Coord cursor, uint32_t number);
|
||||||
|
void cursor_left(Editor *editor, uint32_t number);
|
||||||
|
void cursor_right(Editor *editor, uint32_t number);
|
||||||
|
void scroll_up(Editor *editor, int32_t number);
|
||||||
|
void scroll_down(Editor *editor, uint32_t number);
|
||||||
|
void ensure_cursor(Editor *editor);
|
||||||
|
void ensure_scroll(Editor *editor);
|
||||||
|
void handle_editor_event(Editor *editor, KeyEvent event);
|
||||||
|
void edit_erase(Editor *editor, Coord pos, int64_t len);
|
||||||
|
void edit_insert(Editor *editor, Coord pos, char *data, uint32_t len);
|
||||||
|
void edit_replace(Editor *editor, Coord start, Coord end, const char *text,
|
||||||
|
uint32_t len);
|
||||||
|
Coord editor_hit_test(Editor *editor, uint32_t x, uint32_t y);
|
||||||
|
char *get_selection(Editor *editor, uint32_t *out_len, Coord *out_start);
|
||||||
|
void selection_bounds(Editor *editor, Coord *out_start, Coord *out_end);
|
||||||
|
void editor_worker(Editor *editor);
|
||||||
|
void move_line_down(Editor *editor);
|
||||||
|
void move_line_up(Editor *editor);
|
||||||
|
void word_boundaries(Editor *editor, Coord coord, uint32_t *prev_col,
|
||||||
|
uint32_t *next_col, uint32_t *prev_clusters,
|
||||||
|
uint32_t *next_clusters);
|
||||||
|
void word_boundaries_exclusive(Editor *editor, Coord coord, uint32_t *prev_col,
|
||||||
|
uint32_t *next_col);
|
||||||
|
void editor_lsp_handle(Editor *editor, json msg);
|
||||||
|
void apply_lsp_edits(Editor *editor, std::vector<TextEdit> edits, bool move);
|
||||||
|
void completion_resolve_doc(Editor *editor);
|
||||||
|
void complete_accept(Editor *editor);
|
||||||
|
void complete_next(Editor *editor);
|
||||||
|
void complete_prev(Editor *editor);
|
||||||
|
void complete_select(Editor *editor, uint8_t index);
|
||||||
|
void handle_completion(Editor *editor, KeyEvent event);
|
||||||
|
|
||||||
|
inline void apply_hook_insertion(Editor *editor, uint32_t line, uint32_t rows) {
|
||||||
|
for (auto &hook : editor->hooks)
|
||||||
|
if (hook > line)
|
||||||
|
hook += rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void apply_hook_deletion(Editor *editor, uint32_t removal_start,
|
||||||
|
uint32_t removal_end) {
|
||||||
|
for (auto &hook : editor->hooks)
|
||||||
|
if (hook > removal_start)
|
||||||
|
hook -= removal_end - removal_start + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void utf8_normalize_edit(Editor *editor, TextEdit *edit) {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
if (edit->start.row > editor->root->line_count) {
|
||||||
|
edit->start.row = editor->root->line_count;
|
||||||
|
edit->start.col = UINT32_MAX;
|
||||||
|
}
|
||||||
|
if (edit->end.row > editor->root->line_count) {
|
||||||
|
edit->end.row = editor->root->line_count;
|
||||||
|
edit->end.col = UINT32_MAX;
|
||||||
|
}
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, edit->start.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (edit->start.col < len)
|
||||||
|
edit->start.col = utf16_offset_to_utf8(line, len, edit->start.col);
|
||||||
|
else
|
||||||
|
edit->start.col = len;
|
||||||
|
if (edit->end.row == edit->start.row) {
|
||||||
|
if (edit->end.col < len)
|
||||||
|
edit->end.col = utf16_offset_to_utf8(line, len, edit->end.col);
|
||||||
|
else
|
||||||
|
edit->end.col = len;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
it = begin_l_iter(editor->root, edit->end.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (edit->end.col < len)
|
||||||
|
edit->end.col = utf16_offset_to_utf8(line, len, edit->end.col);
|
||||||
|
else
|
||||||
|
edit->end.col = len;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
24
include/editor/helpers.h
Normal file
24
include/editor/helpers.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef EDITOR_HELPERS_H
|
||||||
|
#define EDITOR_HELPERS_H
|
||||||
|
|
||||||
|
#include "editor/editor.h"
|
||||||
|
|
||||||
|
void insert_str(Editor *editor, char *c, uint32_t len);
|
||||||
|
void insert_char(Editor *editor, char c);
|
||||||
|
void normal_mode(Editor *editor);
|
||||||
|
void backspace_edit(Editor *editor);
|
||||||
|
void delete_prev_word(Editor *editor);
|
||||||
|
void delete_next_word(Editor *editor);
|
||||||
|
void clear_hooks_at_line(Editor *editor, uint32_t line);
|
||||||
|
void cursor_prev_word(Editor *editor);
|
||||||
|
void cursor_next_word(Editor *editor);
|
||||||
|
void select_all(Editor *editor);
|
||||||
|
void fetch_lsp_hover(Editor *editor);
|
||||||
|
void handle_mouse(Editor *editor, KeyEvent event);
|
||||||
|
void indent_current_line(Editor *editor);
|
||||||
|
void dedent_current_line(Editor *editor);
|
||||||
|
void paste(Editor *editor);
|
||||||
|
void copy(Editor *editor);
|
||||||
|
void cut(Editor *editor);
|
||||||
|
|
||||||
|
#endif
|
||||||
152
include/editor/indents.h
Normal file
152
include/editor/indents.h
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
#ifndef EDITOR_INDENTS_H
|
||||||
|
#define EDITOR_INDENTS_H
|
||||||
|
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
static const std::unordered_map<std::string, uint8_t> kLangtoIndent = {
|
||||||
|
{"make", 1}, {"yaml", 2}};
|
||||||
|
|
||||||
|
// this indents the newline one level when the line (on the curser before \n is
|
||||||
|
// inserted) matches this at its end (stripped of whitespace)
|
||||||
|
static const std::unordered_map<std::string, const std::vector<std::string>>
|
||||||
|
kLangtoBlockStartsEnd = {
|
||||||
|
{"bash", {"then", "do", "in", "{", "(", "\\", "&&", "||", "|"}},
|
||||||
|
{"c", {"{", "(", ":"}},
|
||||||
|
{"cpp", {"{", "(", ":"}},
|
||||||
|
{"h", {"{", "(", ":"}},
|
||||||
|
{"css", {"{", "("}},
|
||||||
|
{"fish", {"{", "(", "^", "&&", "||", "|"}},
|
||||||
|
{"go", {"{", "(", ":"}},
|
||||||
|
{"gomod", {"{", "(", ":"}},
|
||||||
|
{"haskell", {"do", "where", "then", "else", "of"}},
|
||||||
|
{"javascript", {"{", "(", "[", ":"}},
|
||||||
|
{"typescript", {"{", "(", "[", ":"}},
|
||||||
|
{"json", {"{", "[", ":"}},
|
||||||
|
{"jsonc", {"{", "[", ":"}},
|
||||||
|
{"ruby", {"then", "else", "begin", "{", "(", "["}},
|
||||||
|
{"lua", {"then", "do", "else", "repeat", "{", "(", "["}},
|
||||||
|
{"python", {":", "(", "[", "{"}},
|
||||||
|
{"rust", {"{", "(", "[", ":"}},
|
||||||
|
{"php", {"{", "(", "[", ":"}},
|
||||||
|
{"nginx", {"{"}},
|
||||||
|
{"yaml", {":"}},
|
||||||
|
{"sql", {"("}},
|
||||||
|
{"make", {":"}},
|
||||||
|
{"gdscript", {":", "(", "[", "{"}},
|
||||||
|
};
|
||||||
|
|
||||||
|
// this indents the newline one level when the line (on the curser before \n is
|
||||||
|
// inserted) matches this at its start (stripped of whitespace)
|
||||||
|
static const std::unordered_map<std::string, const std::vector<std::string>>
|
||||||
|
kLangtoBlockStartsStart = {
|
||||||
|
{"c", {"if", "for", "while"}},
|
||||||
|
{"cpp", {"if", "for", "while"}},
|
||||||
|
{"h", {"if", "for", "while"}},
|
||||||
|
{"fish", {"if", "else", "for", "while", "switch", "case", "function"}},
|
||||||
|
{"javascript", {"if", "for", "while"}},
|
||||||
|
{"typescript", {"if", "for", "while"}},
|
||||||
|
{"ruby",
|
||||||
|
{"if", "do", "when", "rescue", "class", "module", "def", "unless",
|
||||||
|
"until", "elsif", "ensure"}},
|
||||||
|
{"lua", {"function"}},
|
||||||
|
{"nginx", {"{"}},
|
||||||
|
};
|
||||||
|
|
||||||
|
// This dedents the line (under the cursor before \n is inserted) when the line
|
||||||
|
// matches this fully (stripped of whitespace)
|
||||||
|
static const std::unordered_map<std::string, const std::vector<std::string>>
|
||||||
|
kLangtoBlockEndsFull = {
|
||||||
|
{"bash", {"fi", "done", "esac", "}", ")"}},
|
||||||
|
{"c", {"}", ")"}},
|
||||||
|
{"cpp", {"}", ")"}},
|
||||||
|
{"h", {"}", ")"}},
|
||||||
|
{"css", {"}", ")"}},
|
||||||
|
{"fish", {"end"}},
|
||||||
|
{"go", {"}", ")"}},
|
||||||
|
{"gomod", {"}", ")"}},
|
||||||
|
{"javascript", {"}", ")", "]"}},
|
||||||
|
{"typescript", {"}", ")", "]"}},
|
||||||
|
{"json", {"}", "]"}},
|
||||||
|
{"jsonc", {"}", "]"}},
|
||||||
|
{"ruby", {"end", "else", "}", ")", "]"}},
|
||||||
|
{"lua", {"else", "}", ")", "]"}},
|
||||||
|
{"python", {"}", ")", "]", "else:"}},
|
||||||
|
{"rust", {"}", ")", "]"}},
|
||||||
|
{"php",
|
||||||
|
{"}", ")", "]", "else:", "endif;", "endfor;", "endwhile;",
|
||||||
|
"endswitch;", "endcase;", "endfunction;"}},
|
||||||
|
{"nginx", {"}"}},
|
||||||
|
{"sql", {")"}},
|
||||||
|
{"gdscript", {"}", ")", "]"}},
|
||||||
|
};
|
||||||
|
|
||||||
|
// This dedents the line (under the cursor before \n is inserted) when the line
|
||||||
|
// matches this at its start (stripped of whitespace)
|
||||||
|
static const std::unordered_map<std::string, const std::vector<std::string>>
|
||||||
|
kLangtoBlockEndsStart = {
|
||||||
|
{"c", {"case", "default:", "} else"}},
|
||||||
|
{"cpp", {"case", "default:", "} else"}},
|
||||||
|
{"h", {"case", "default:", "} else"}},
|
||||||
|
{"fish", {"else if"}},
|
||||||
|
{"go", {"case", "default:", "} else"}},
|
||||||
|
{"gomod", {"}", ")"}},
|
||||||
|
{"javascript", {"case", "default:"}},
|
||||||
|
{"typescript", {"case", "default:"}},
|
||||||
|
{"json", {"}", "]"}},
|
||||||
|
{"python", {"elif"}},
|
||||||
|
{"jsonc", {"}", "]"}},
|
||||||
|
{"ruby", {"when", "elsif", "rescue", "ensure"}},
|
||||||
|
{"lua", {"end", "elseif", "until"}},
|
||||||
|
{"rust", {"case", "default:", "} else"}},
|
||||||
|
{"php", {"case", "default:", "} else"}},
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IndentationEngine {
|
||||||
|
// tabs = 1, spaces = 2+
|
||||||
|
uint8_t indent = 0;
|
||||||
|
struct Editor *editor = nullptr;
|
||||||
|
|
||||||
|
void compute_indent(Editor *n_editor);
|
||||||
|
void insert_new_line(Coord cursor);
|
||||||
|
void insert_tab(Coord cursor);
|
||||||
|
uint32_t set_indent(uint32_t row, int64_t indent_level);
|
||||||
|
uint32_t indent_line(uint32_t row);
|
||||||
|
uint32_t dedent_line(uint32_t row);
|
||||||
|
void indent_block(uint32_t start, uint32_t end);
|
||||||
|
void dedent_block(uint32_t start, uint32_t end);
|
||||||
|
// fixes a autocomplete block's indentation
|
||||||
|
char *block_to_asis(Coord cursor, std::string source, uint32_t *out_len);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// TODO: Ignore comments/strings too
|
||||||
|
// returns the indent level of the line itself or of the previous non-empty
|
||||||
|
uint32_t indent_expected(uint32_t row);
|
||||||
|
// returns the indent level of the line
|
||||||
|
uint32_t indent_real(char *line, uint32_t len);
|
||||||
|
};
|
||||||
|
|
||||||
|
inline static bool ends_with(const std::string &str,
|
||||||
|
const std::string &suffix) {
|
||||||
|
const size_t str_len = str.size();
|
||||||
|
const size_t suf_len = suffix.size();
|
||||||
|
if (suf_len > str_len)
|
||||||
|
return false;
|
||||||
|
for (size_t i = 0; i < suf_len; i++)
|
||||||
|
if (str[str_len - suf_len + i] != suffix[i])
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static bool starts_with(const std::string &str,
|
||||||
|
const std::string &prefix) {
|
||||||
|
const size_t str_len = str.size();
|
||||||
|
const size_t pre_len = prefix.size();
|
||||||
|
if (pre_len > str_len)
|
||||||
|
return false;
|
||||||
|
for (size_t i = 0; i < pre_len; i++)
|
||||||
|
if (str[i] != prefix[i])
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
#ifndef ROPE_H
|
#ifndef ROPE_H
|
||||||
#define ROPE_H
|
#define ROPE_H
|
||||||
|
|
||||||
#include "./utils.h"
|
#include "pch.h"
|
||||||
#include <cstdint>
|
#include "utils/utils.h"
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#define MIN_CHUNK_SIZE 64 // 64 Bytes
|
#define MIN_CHUNK_SIZE 64 // 64 Bytes
|
||||||
#define MAX_CHUNK_SIZE 1024 * 8 // 8192 Bytes (8 KiB)
|
#define MAX_CHUNK_SIZE 1024 * 8 // 8192 Bytes (8 KiB)
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
||||||
#define DEPTH(n) ((n) ? (n)->depth : 0)
|
#define DEPTH(n) ((n) ? (n)->depth : 0)
|
||||||
|
|
||||||
// Rope node definition
|
// Rope node definition
|
||||||
@@ -26,8 +23,9 @@ typedef struct LineIterator {
|
|||||||
Knot *node;
|
Knot *node;
|
||||||
uint8_t top;
|
uint8_t top;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
uint32_t line;
|
|
||||||
Knot *stack[64];
|
Knot *stack[64];
|
||||||
|
char *buffer;
|
||||||
|
size_t capacity;
|
||||||
} LineIterator;
|
} LineIterator;
|
||||||
|
|
||||||
typedef struct LeafIterator {
|
typedef struct LeafIterator {
|
||||||
@@ -93,6 +91,9 @@ Knot *erase(Knot *node, uint32_t offset, uint32_t len);
|
|||||||
// returns a null terminated string, should be freed by the caller
|
// returns a null terminated string, should be freed by the caller
|
||||||
char *read(Knot *root, uint32_t offset, uint32_t len);
|
char *read(Knot *root, uint32_t offset, uint32_t len);
|
||||||
|
|
||||||
|
// Used to read into an existing buffer
|
||||||
|
void read_into(Knot *node, uint32_t offset, uint32_t len, char *dest);
|
||||||
|
|
||||||
// Used to split the rope into left and right ropes
|
// Used to split the rope into left and right ropes
|
||||||
// node is the rope to be split (it is no longer valid after call / do not free)
|
// node is the rope to be split (it is no longer valid after call / do not free)
|
||||||
// offset is the position of the split relative to the start of the rope
|
// offset is the position of the split relative to the start of the rope
|
||||||
@@ -100,7 +101,7 @@ char *read(Knot *root, uint32_t offset, uint32_t len);
|
|||||||
void split(Knot *node, uint32_t offset, Knot **left, Knot **right);
|
void split(Knot *node, uint32_t offset, Knot **left, Knot **right);
|
||||||
|
|
||||||
// Used to convert a byte offset to a line number that contains that byte
|
// Used to convert a byte offset to a line number that contains that byte
|
||||||
uint32_t byte_to_line(Knot *node, uint32_t offset);
|
uint32_t byte_to_line(Knot *node, uint32_t offset, uint32_t *out_col);
|
||||||
|
|
||||||
// Used to convert a line number to a byte offset (start of the line)
|
// Used to convert a line number to a byte offset (start of the line)
|
||||||
// also sets out_len to the length of the line
|
// also sets out_len to the length of the line
|
||||||
@@ -113,10 +114,18 @@ LineIterator *begin_l_iter(Knot *root, uint32_t start_line);
|
|||||||
|
|
||||||
// Each subsequent call returns the next line as a null terminated string
|
// Each subsequent call returns the next line as a null terminated string
|
||||||
// `it` is the iterator returned from begin_l_iter
|
// `it` is the iterator returned from begin_l_iter
|
||||||
// After getting the necessary lines free the iterator (no need to go upto the
|
// After getting the necessary lines free the iterator (no need to go upto
|
||||||
// end) returns null if there are no more lines All return strings `must` be
|
// the end) returns null if there are no more lines All return strings
|
||||||
// freed by the caller
|
// `must` be freed by the caller
|
||||||
char *next_line(LineIterator *it);
|
char *next_line(LineIterator *it, uint32_t *out_len);
|
||||||
|
|
||||||
|
// Returns the previous line as a null terminated string
|
||||||
|
// `it` is the iterator returned from begin_l_iter
|
||||||
|
// it can be used to iterate backwards
|
||||||
|
// and can be used along with next_line
|
||||||
|
// doing prev_line then next_line or vice versa will return the same line
|
||||||
|
// `out_len` is set to the length of the returned string
|
||||||
|
char *prev_line(LineIterator *it, uint32_t *out_len);
|
||||||
|
|
||||||
// Used to start an iterator over leaf data
|
// Used to start an iterator over leaf data
|
||||||
// root is the root of the rope
|
// root is the root of the rope
|
||||||
@@ -153,9 +162,11 @@ char *leaf_from_offset(Knot *root, uint32_t start_offset, uint32_t *out_len);
|
|||||||
// compliant) I.e some forms of backtracking etc. are not supported
|
// compliant) I.e some forms of backtracking etc. are not supported
|
||||||
// root is the root of the rope to be searched
|
// root is the root of the rope to be searched
|
||||||
// Returns a vector of pairs of start and length offsets (in bytes)
|
// Returns a vector of pairs of start and length offsets (in bytes)
|
||||||
std::vector<std::pair<size_t, size_t>> search_rope(Knot *root,
|
std::vector<std::pair<size_t, size_t>> search_rope_dfa(Knot *root,
|
||||||
const char *pattern);
|
const char *pattern);
|
||||||
|
|
||||||
|
std::vector<Match> search_rope(Knot *root, const char *pattern);
|
||||||
|
|
||||||
// Helper function to free the rope
|
// Helper function to free the rope
|
||||||
// root is the root of the rope
|
// root is the root of the rope
|
||||||
// the root is no longer valid after call
|
// the root is no longer valid after call
|
||||||
116
include/io/sysio.h
Normal file
116
include/io/sysio.h
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
#ifndef UI_H
|
||||||
|
#define UI_H
|
||||||
|
|
||||||
|
#include "pch.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
#define KEY_CHAR 0
|
||||||
|
#define KEY_SPECIAL 1
|
||||||
|
#define KEY_MOUSE 2
|
||||||
|
#define KEY_PASTE 3
|
||||||
|
#define KEY_NONE 4
|
||||||
|
|
||||||
|
#define KEY_UP 0
|
||||||
|
#define KEY_DOWN 1
|
||||||
|
#define KEY_LEFT 2
|
||||||
|
#define KEY_RIGHT 3
|
||||||
|
#define KEY_DELETE 4
|
||||||
|
|
||||||
|
#define KEY_ESC '\x1b'
|
||||||
|
|
||||||
|
#define PRESS 0
|
||||||
|
#define RELEASE 1
|
||||||
|
#define DRAG 2
|
||||||
|
#define SCROLL 3
|
||||||
|
|
||||||
|
#define LEFT_BTN 0
|
||||||
|
#define MIDDLE_BTN 1
|
||||||
|
#define RIGHT_BTN 2
|
||||||
|
#define SCROLL_BTN 3
|
||||||
|
#define NONE_BTN 4
|
||||||
|
|
||||||
|
#define SCROLL_UP 0
|
||||||
|
#define SCROLL_DOWN 1
|
||||||
|
#define SCROLL_LEFT 2
|
||||||
|
#define SCROLL_RIGHT 3
|
||||||
|
|
||||||
|
#define ALT 1
|
||||||
|
#define CNTRL 2
|
||||||
|
#define CNTRL_ALT 3
|
||||||
|
#define SHIFT 4
|
||||||
|
|
||||||
|
#define DEFAULT 0
|
||||||
|
#define BLOCK 2
|
||||||
|
#define UNDERLINE 4
|
||||||
|
#define CURSOR 6
|
||||||
|
|
||||||
|
enum CellFlags : uint8_t {
|
||||||
|
CF_NONE = 0,
|
||||||
|
CF_ITALIC = 1 << 0,
|
||||||
|
CF_BOLD = 1 << 1,
|
||||||
|
CF_UNDERLINE = 1 << 2,
|
||||||
|
CF_STRIKETHROUGH = 1 << 3
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ScreenCell {
|
||||||
|
std::string utf8 = std::string("");
|
||||||
|
uint8_t width = 1;
|
||||||
|
uint32_t fg = 0;
|
||||||
|
uint32_t bg = 0;
|
||||||
|
uint8_t flags = CF_NONE;
|
||||||
|
uint32_t ul_color = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct KeyEvent {
|
||||||
|
/* KEY_CHAR, KEY_SPECIAL, KEY_MOUSE, KEY_PASTE, KEY_NONE */
|
||||||
|
uint8_t key_type;
|
||||||
|
|
||||||
|
/* the character / string if key_type == KEY_CHAR or KEY_PASTE */
|
||||||
|
char *c;
|
||||||
|
/* length of c */
|
||||||
|
uint32_t len;
|
||||||
|
|
||||||
|
/* KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_DELETE if key_type ==
|
||||||
|
* KEY_SPECIAL */
|
||||||
|
uint8_t special_key;
|
||||||
|
/* ALT, CNTRL, CNTRL_ALT, SHIFT if key_type == KEY_SPECIAL */
|
||||||
|
uint8_t special_modifier;
|
||||||
|
|
||||||
|
/* column of mouse click */
|
||||||
|
uint8_t mouse_x;
|
||||||
|
/* row of mouse click */
|
||||||
|
uint8_t mouse_y;
|
||||||
|
/* LEFT_BTN, MIDDLE_BTN, RIGHT_BTN, SCROLL_BTN, NONE_BTN if key_type ==
|
||||||
|
* KEY_MOUSE */
|
||||||
|
uint8_t mouse_button;
|
||||||
|
/* PRESS, RELEASE, DRAG, SCROLL if key_type == KEY_MOUSE */
|
||||||
|
uint8_t mouse_state;
|
||||||
|
/* SCROLL_UP, SCROLL_DOWN, SCROLL_LEFT, SCROLL_RIGHT if key_type ==
|
||||||
|
* KEY_MOUSE and mouse_state == SCROLL */
|
||||||
|
uint8_t mouse_direction;
|
||||||
|
/* ALT, CNTRL, CNTRL_ALT, SHIFT if key_type == KEY_MOUSE */
|
||||||
|
uint8_t mouse_modifier;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool is_empty_cell(const ScreenCell &c) {
|
||||||
|
return c.utf8.empty() || c.utf8 == " " || c.utf8 == "\x1b";
|
||||||
|
}
|
||||||
|
|
||||||
|
Coord start_screen();
|
||||||
|
void end_screen();
|
||||||
|
void update(uint32_t row, uint32_t col, std::string utf8, uint32_t fg,
|
||||||
|
uint32_t bg, uint8_t flags);
|
||||||
|
void update(uint32_t row, uint32_t col, const char *utf8, uint32_t fg,
|
||||||
|
uint32_t bg, uint8_t flags);
|
||||||
|
void update(uint32_t row, uint32_t col, std::string utf8, uint32_t fg,
|
||||||
|
uint32_t bg, uint8_t flags, uint32_t ul_color);
|
||||||
|
void update(uint32_t row, uint32_t col, const char *utf8, uint32_t fg,
|
||||||
|
uint32_t bg, uint8_t flags, uint32_t ul_color);
|
||||||
|
void set_cursor(uint8_t row, uint8_t col, uint32_t type,
|
||||||
|
bool show_cursor_param);
|
||||||
|
void render();
|
||||||
|
Coord get_size();
|
||||||
|
|
||||||
|
KeyEvent read_key();
|
||||||
|
|
||||||
|
#endif
|
||||||
92
include/lsp/lsp.h
Normal file
92
include/lsp/lsp.h
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#ifndef LSP_H
|
||||||
|
#define LSP_H
|
||||||
|
|
||||||
|
#include "editor/editor.h"
|
||||||
|
#include "pch.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
struct LSPPending {
|
||||||
|
std::string method;
|
||||||
|
Editor *editor = nullptr;
|
||||||
|
|
||||||
|
std::function<void(Editor *, std::string, json)> callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LSPOpenRequest {
|
||||||
|
Language language;
|
||||||
|
Editor *editor;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LSPInstance {
|
||||||
|
std::shared_mutex mtx;
|
||||||
|
const LSP *lsp;
|
||||||
|
std::string root_dir;
|
||||||
|
int pid{-1};
|
||||||
|
int stdin_fd{-1};
|
||||||
|
int stdout_fd{-1};
|
||||||
|
std::atomic<bool> initialized = false;
|
||||||
|
std::atomic<bool> exited = false;
|
||||||
|
bool incremental_sync = false;
|
||||||
|
bool allow_hover = false;
|
||||||
|
bool allow_completion = false;
|
||||||
|
bool allow_resolve = false;
|
||||||
|
bool allow_formatting = false;
|
||||||
|
bool allow_formatting_on_type = false;
|
||||||
|
bool is_utf8 = false;
|
||||||
|
std::vector<char> format_chars;
|
||||||
|
std::vector<char> trigger_chars;
|
||||||
|
std::vector<char> end_chars;
|
||||||
|
uint32_t last_id = 0;
|
||||||
|
Queue<json> inbox;
|
||||||
|
Queue<json> outbox;
|
||||||
|
Queue<std::pair<Language, Editor *>> open_queue;
|
||||||
|
std::unordered_map<uint32_t, LSPPending *> pending;
|
||||||
|
std::vector<Editor *> editors;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern std::shared_mutex active_lsps_mtx;
|
||||||
|
extern std::unordered_map<std::string, std::shared_ptr<LSPInstance>>
|
||||||
|
active_lsps;
|
||||||
|
extern Queue<LSPOpenRequest> lsp_open_queue;
|
||||||
|
|
||||||
|
static json client_capabilities = {
|
||||||
|
{"general", {{"positionEncodings", {"utf-16"}}}},
|
||||||
|
{"textDocument",
|
||||||
|
{{"publishDiagnostics", {{"relatedInformation", true}}},
|
||||||
|
{"hover", {{"contentFormat", {"markdown", "plaintext"}}}},
|
||||||
|
{"formatting", {{"dynamicRegistration", false}}},
|
||||||
|
{"onTypeFormatting", {{"dynamicRegistration", false}}},
|
||||||
|
{"completion",
|
||||||
|
{{"completionItem",
|
||||||
|
{{"commitCharactersSupport", true},
|
||||||
|
{"dynamicRegistration", false},
|
||||||
|
{"snippetSupport", true},
|
||||||
|
{"documentationFormat", {"markdown", "plaintext"}},
|
||||||
|
{"resolveSupport", {{"properties", {"documentation"}}}},
|
||||||
|
{"insertReplaceSupport", true},
|
||||||
|
{"labelDetailsSupport", true},
|
||||||
|
{"insertTextModeSupport", {{"valueSet", {1, 2}}}},
|
||||||
|
{"deprecatedSupport", true}}},
|
||||||
|
{"completionItemKind",
|
||||||
|
{{"valueSet", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||||
|
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}}}},
|
||||||
|
{"contextSupport", true},
|
||||||
|
{"insertTextMode", 1}}}}}};
|
||||||
|
|
||||||
|
void lsp_send(std::shared_ptr<LSPInstance> lsp, json message,
|
||||||
|
LSPPending *pending);
|
||||||
|
void lsp_worker();
|
||||||
|
|
||||||
|
std::shared_ptr<LSPInstance> get_or_init_lsp(std::string lsp_id);
|
||||||
|
void clean_lsp(std::shared_ptr<LSPInstance> lsp, std::string lsp_id);
|
||||||
|
void close_lsp(std::string lsp_id);
|
||||||
|
std::optional<json> read_lsp_message(int fd);
|
||||||
|
|
||||||
|
void open_editor(std::shared_ptr<LSPInstance> lsp,
|
||||||
|
std::pair<Language, Editor *> entry);
|
||||||
|
void request_add_to_lsp(Language language, Editor *editor);
|
||||||
|
void add_to_lsp(Language language, Editor *editor);
|
||||||
|
void remove_from_lsp(Editor *editor);
|
||||||
|
void lsp_handle(std::shared_ptr<LSPInstance> lsp, json message);
|
||||||
|
|
||||||
|
#endif
|
||||||
19
include/main.h
Normal file
19
include/main.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef MAIN_H
|
||||||
|
#define MAIN_H
|
||||||
|
|
||||||
|
#include "pch.h"
|
||||||
|
#include "ui/bar.h"
|
||||||
|
|
||||||
|
#define NORMAL 0
|
||||||
|
#define INSERT 1
|
||||||
|
#define SELECT 2
|
||||||
|
#define RUNNER 3
|
||||||
|
#define JUMPER 4
|
||||||
|
|
||||||
|
extern std::atomic<bool> running;
|
||||||
|
extern std::atomic<uint8_t> mode;
|
||||||
|
extern std::vector<struct Editor *> editors;
|
||||||
|
extern uint8_t current_editor;
|
||||||
|
extern Bar bar;
|
||||||
|
|
||||||
|
#endif
|
||||||
58
include/pch.h
Normal file
58
include/pch.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#ifndef PCH_H
|
||||||
|
#define PCH_H
|
||||||
|
|
||||||
|
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||||
|
#define PCRE_WORKSPACE_SIZE 512
|
||||||
|
|
||||||
|
#include <mruby.h>
|
||||||
|
#include <mruby/array.h>
|
||||||
|
#include <mruby/compile.h>
|
||||||
|
#include <mruby/hash.h>
|
||||||
|
#include <mruby/irep.h>
|
||||||
|
#include <mruby/string.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <pcre2.h>
|
||||||
|
extern "C" {
|
||||||
|
#include "libgrapheme/grapheme.h"
|
||||||
|
#include "unicode_width/unicode_width.h"
|
||||||
|
}
|
||||||
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
|
#include <cctype>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <deque>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <functional>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
|
#include <shared_mutex>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stack>
|
||||||
|
#include <string.h>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/poll.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using json = nlohmann::json;
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
#endif
|
||||||
45
include/scripting/decl.h
Normal file
45
include/scripting/decl.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef SCRIPTING_DECL_H
|
||||||
|
#define SCRIPTING_DECL_H
|
||||||
|
|
||||||
|
#include "syntax/decl.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
extern std::unordered_map<std::string, std::pair<mrb_value, mrb_value>>
|
||||||
|
custom_highlighters;
|
||||||
|
|
||||||
|
struct BarLight {
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t end;
|
||||||
|
Highlight highlight;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BarLine {
|
||||||
|
std::string line;
|
||||||
|
std::vector<BarLight> highlights;
|
||||||
|
|
||||||
|
Highlight get_highlight(uint32_t x) {
|
||||||
|
for (auto &hl : highlights) {
|
||||||
|
if (hl.start <= x && x <= hl.end)
|
||||||
|
return hl.highlight;
|
||||||
|
}
|
||||||
|
return {0xFFFFFF, 0, 0};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void setup_ruby_bindings(mrb_state *mrb, RClass *C_module);
|
||||||
|
void ruby_start();
|
||||||
|
void ruby_shutdown();
|
||||||
|
void load_theme();
|
||||||
|
void load_languages_info();
|
||||||
|
uint8_t read_line_endings();
|
||||||
|
void load_custom_highlighters();
|
||||||
|
mrb_value parse_custom(std::vector<Token> *tokens, mrb_value parser_block,
|
||||||
|
const char *line, uint32_t len, mrb_value state,
|
||||||
|
uint32_t c_line);
|
||||||
|
bool custom_compare(mrb_value match_block, mrb_value state1, mrb_value state2);
|
||||||
|
BarLine bar_contents(uint8_t mode, std::string lang_name, uint32_t warnings,
|
||||||
|
std::string lsp_name, std::string filename,
|
||||||
|
std::string foldername, uint32_t line, uint32_t max_line,
|
||||||
|
uint32_t width);
|
||||||
|
|
||||||
|
#endif
|
||||||
354
include/scripting/libcrib.rb
Normal file
354
include/scripting/libcrib.rb
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
module C
|
||||||
|
@lsp_config = {
|
||||||
|
"clangd" => [
|
||||||
|
"--background-index",
|
||||||
|
"--clang-tidy",
|
||||||
|
"--completion-style=detailed",
|
||||||
|
"--header-insertion=never",
|
||||||
|
"--pch-storage=memory",
|
||||||
|
"--limit-results=50",
|
||||||
|
"--log=error"
|
||||||
|
],
|
||||||
|
"ruby-lsp" => [],
|
||||||
|
"solargraph" => ["stdio"],
|
||||||
|
"bash-language-server" => ["start"],
|
||||||
|
"vscode-css-language-server" => ["--stdio"],
|
||||||
|
"vscode-json-language-server" => ["--stdio"],
|
||||||
|
"fish-lsp" => ["start"],
|
||||||
|
"gopls" => ["serve"],
|
||||||
|
"haskell-language-server" => ["lsp"],
|
||||||
|
"emmet-language-server" => ["--stdio"],
|
||||||
|
"typescript-language-server" => ["--stdio"],
|
||||||
|
"lua-language-server" => [],
|
||||||
|
"pyright-langserver" => ["--stdio"],
|
||||||
|
"rust-analyzer" => [],
|
||||||
|
"intelephense" => ["--stdio"],
|
||||||
|
"marksman" => ["server"],
|
||||||
|
"nginx-language-server" => [],
|
||||||
|
"taplo" => ["lsp", "stdio"],
|
||||||
|
"yaml-language-server" => ["--stdio"],
|
||||||
|
"sqls" => ["serve"],
|
||||||
|
"make-language-server" => [],
|
||||||
|
"sql-language-server" => ["up", "--method", "stdio"]
|
||||||
|
}
|
||||||
|
@languages = {
|
||||||
|
c: {
|
||||||
|
color: 0x555555,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["c"],
|
||||||
|
lsp: "clangd"
|
||||||
|
},
|
||||||
|
cpp: {
|
||||||
|
color: 0x00599C,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["cpp", "cc", "cxx"],
|
||||||
|
lsp: "clangd"
|
||||||
|
},
|
||||||
|
h: {
|
||||||
|
color: 0xA8B9CC,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["h", "hpp"],
|
||||||
|
lsp: "clangd"
|
||||||
|
},
|
||||||
|
css: {
|
||||||
|
color: 0x36a3d9,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["css"],
|
||||||
|
lsp: "vscode-css-language-server"
|
||||||
|
},
|
||||||
|
fish: {
|
||||||
|
color: 0x4d5a5e,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["fish"],
|
||||||
|
lsp: "fish-lsp"
|
||||||
|
},
|
||||||
|
go: {
|
||||||
|
color: 0x00add8,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["go"],
|
||||||
|
lsp: "gopls"
|
||||||
|
},
|
||||||
|
gomod: {
|
||||||
|
color: 0x00add8,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["mod"],
|
||||||
|
lsp: "gopls"
|
||||||
|
},
|
||||||
|
haskell: {
|
||||||
|
color: 0xa074c4,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["hs", "lhs"],
|
||||||
|
lsp: "haskell-language-server"
|
||||||
|
},
|
||||||
|
html: {
|
||||||
|
color: 0xef8a91,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["html", "htm"],
|
||||||
|
lsp: "emmet-language-server"
|
||||||
|
},
|
||||||
|
javascript: {
|
||||||
|
color: 0xf0df8a,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["js"],
|
||||||
|
lsp: "typescript-language-server"
|
||||||
|
},
|
||||||
|
typescript: {
|
||||||
|
color: 0x36a3d9,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["ts"],
|
||||||
|
lsp: "typescript-language-server"
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
color: 0xcbcb41,
|
||||||
|
symbol: "{}",
|
||||||
|
extensions: ["json"],
|
||||||
|
lsp: "vscode-json-language-server"
|
||||||
|
},
|
||||||
|
jsonc: {
|
||||||
|
color: 0xcbcb41,
|
||||||
|
symbol: "{}",
|
||||||
|
extensions: ["jsonc"],
|
||||||
|
lsp: "vscode-json-language-server"
|
||||||
|
},
|
||||||
|
erb: {
|
||||||
|
color: 0x6e1516,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["erb"],
|
||||||
|
lsp: "ruby-lsp"
|
||||||
|
},
|
||||||
|
lua: {
|
||||||
|
color: 0x36a3d9,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["lua"],
|
||||||
|
lsp: "lua-language-server"
|
||||||
|
},
|
||||||
|
python: {
|
||||||
|
color: 0x95e6cb,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["py"],
|
||||||
|
lsp: "pyright"
|
||||||
|
},
|
||||||
|
rust: {
|
||||||
|
color: 0xdea584,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["rs"],
|
||||||
|
lsp: "rust-analyzer"
|
||||||
|
},
|
||||||
|
php: {
|
||||||
|
color: 0xa074c4,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["php"],
|
||||||
|
lsp: "intelephense"
|
||||||
|
},
|
||||||
|
markdown: {
|
||||||
|
color: 0x36a3d9,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["md", "markdown"],
|
||||||
|
lsp: "marksman"
|
||||||
|
},
|
||||||
|
nginx: {
|
||||||
|
color: 0x6d8086,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["conf"],
|
||||||
|
lsp: "nginx-language-server"
|
||||||
|
},
|
||||||
|
toml: {
|
||||||
|
color: 0x36a3d9,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["toml"],
|
||||||
|
lsp: "taplo"
|
||||||
|
},
|
||||||
|
yaml: {
|
||||||
|
color: 0x6d8086,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["yml", "yaml"],
|
||||||
|
lsp: "yaml-language-server"
|
||||||
|
},
|
||||||
|
sql: {
|
||||||
|
color: 0xdad8d8,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["sql"],
|
||||||
|
lsp: "sqls"
|
||||||
|
},
|
||||||
|
make: {
|
||||||
|
color: 0x4e5c61,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["Makefile", "makefile"],
|
||||||
|
lsp: "make-language-server"
|
||||||
|
},
|
||||||
|
gdscript: {
|
||||||
|
color: 0x6d8086,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["gd"]
|
||||||
|
},
|
||||||
|
man: {
|
||||||
|
color: 0xdad8d8,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["man"]
|
||||||
|
},
|
||||||
|
diff: {
|
||||||
|
color: 0xDD4C35,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["diff", "patch"]
|
||||||
|
},
|
||||||
|
gitattributes: {
|
||||||
|
color: 0xF05032,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["gitattributes"]
|
||||||
|
},
|
||||||
|
gitignore: {
|
||||||
|
color: 0xF05032,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["gitignore"]
|
||||||
|
},
|
||||||
|
regex: {
|
||||||
|
color: 0x9E9E9E,
|
||||||
|
symbol: ".*",
|
||||||
|
extensions: ["regex"]
|
||||||
|
},
|
||||||
|
ini: {
|
||||||
|
color: 0x6d8086,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["ini"]
|
||||||
|
},
|
||||||
|
ruby: {
|
||||||
|
color: 0xff8087,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["rb"],
|
||||||
|
filenames: ["Gemfile"],
|
||||||
|
lsp: "solargraph"
|
||||||
|
},
|
||||||
|
bash: {
|
||||||
|
color: 0x4d5a5e,
|
||||||
|
symbol: " ",
|
||||||
|
extensions: ["sh"],
|
||||||
|
filenames: ["bash_profile", "bashrc"],
|
||||||
|
lsp: "bash-language-server"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@theme = {
|
||||||
|
:default => { fg: 0xEEEEEE },
|
||||||
|
:shebang => { fg: 0x7DCFFF },
|
||||||
|
:error => { fg: 0xEF5168 },
|
||||||
|
:comment => { fg: 0xAAAAAA, italic: true },
|
||||||
|
:string => { fg: 0xAAD94C },
|
||||||
|
:escape => { fg: 0x7DCFFF },
|
||||||
|
:interpolation => { fg: 0x7DCFFF },
|
||||||
|
:regexp => { fg: 0xD2A6FF },
|
||||||
|
:number => { fg: 0xE6C08A },
|
||||||
|
:true => { fg: 0x7AE93C },
|
||||||
|
:false => { fg: 0xEF5168 },
|
||||||
|
:char => { fg: 0xFFAF70 },
|
||||||
|
:keyword => { fg: 0xFF8F40 },
|
||||||
|
:keywordoperator => { fg: 0xF07178 },
|
||||||
|
:operator => { fg: 0xFFFFFF, italic: true },
|
||||||
|
:function => { fg: 0xFFAF70 },
|
||||||
|
:type => { fg: 0xF07178 },
|
||||||
|
:constant => { fg: 0x7DCFFF },
|
||||||
|
:variableinstance => { fg: 0x95E6CB },
|
||||||
|
:variableglobal => { fg: 0xF07178 },
|
||||||
|
:annotation => { fg: 0x7DCFFF },
|
||||||
|
:directive => { fg: 0xFF8F40 },
|
||||||
|
:label => { fg: 0xD2A6FF },
|
||||||
|
:brace1 => { fg: 0xD2A6FF },
|
||||||
|
:brace2 => { fg: 0xFFAFAF },
|
||||||
|
:brace3 => { fg: 0xFFFF00 },
|
||||||
|
:brace4 => { fg: 0x0FFF0F },
|
||||||
|
:brace5 => { fg: 0xFF0F0F }
|
||||||
|
}
|
||||||
|
@line_endings = :auto_unix
|
||||||
|
@key_handlers = {}
|
||||||
|
@key_binds = {}
|
||||||
|
@highlighters = {}
|
||||||
|
@b_startup = nil
|
||||||
|
@b_shutdown = nil
|
||||||
|
@b_bar = lambda do |info|
|
||||||
|
# mode, lang_name, warnings, lsp_name, filename, foldername, line, max_line, width
|
||||||
|
# puts info.inspect
|
||||||
|
mode_color = 0x82AAFF
|
||||||
|
mode_symbol = " "
|
||||||
|
case info[:mode]
|
||||||
|
when :normal
|
||||||
|
mode_color = 0x82AAFF
|
||||||
|
mode_symbol = " "
|
||||||
|
when :insert
|
||||||
|
mode_color = 0xFF8F40
|
||||||
|
mode_symbol = " "
|
||||||
|
when :select
|
||||||
|
mode_color = 0x9ADE7A
|
||||||
|
mode_symbol = " "
|
||||||
|
when :runner
|
||||||
|
mode_color = 0xFFD700
|
||||||
|
mode_symbol = " "
|
||||||
|
when :jumper
|
||||||
|
mode_color = 0xF29CC3
|
||||||
|
mode_symbol = " "
|
||||||
|
end
|
||||||
|
lang_info = C.languages[info[:lang_name]]
|
||||||
|
filename = File.basename(info[:filename])
|
||||||
|
starting = " #{mode_symbol} #{info[:mode].to_s.upcase} #{lang_info[:symbol]}#{filename}"
|
||||||
|
highlights = []
|
||||||
|
highlights << { fg: 0x0b0e14, bg: mode_color, flags: 1 << 1, start: 0, length: 10 }
|
||||||
|
highlights << { fg: mode_color, bg: 0x33363c, start: 10, length: 1 }
|
||||||
|
highlights << { fg: 0x33363c, bg: 0x24272d, start: 11, length: 1 }
|
||||||
|
highlights << { fg: lang_info[:color], bg: 0x24272d, start: 13, length: 2 }
|
||||||
|
highlights << { fg: 0xced4df, bg: 0x24272d, start: 15, length: filename.length }
|
||||||
|
highlights << { fg: 0x24272d, bg: 0x000000, start: 15 + filename.length, length: 1 }
|
||||||
|
return {
|
||||||
|
text: starting,
|
||||||
|
highlights: highlights
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
attr_accessor :theme, :lsp_config, :languages,
|
||||||
|
:line_endings, :highlighters
|
||||||
|
attr_reader :b_startup, :b_shutdown, :b_extra_highlights, :b_bar
|
||||||
|
|
||||||
|
# def bar=(block)
|
||||||
|
# @b_bar = block
|
||||||
|
# end
|
||||||
|
|
||||||
|
def startup(&block)
|
||||||
|
@b_startup = block
|
||||||
|
end
|
||||||
|
|
||||||
|
def shutdown(&block)
|
||||||
|
@b_shutdown = block
|
||||||
|
end
|
||||||
|
|
||||||
|
def extra_highlights(&block)
|
||||||
|
@b_extra_highlights = block
|
||||||
|
end
|
||||||
|
|
||||||
|
def bind(modes, keys = nil, action = nil, &block)
|
||||||
|
modes = [modes] unless modes.is_a?(Array)
|
||||||
|
if keys.nil?
|
||||||
|
app = self
|
||||||
|
dsl = Object.new
|
||||||
|
dsl.define_singleton_method(:set) do |k, act = nil, &blk|
|
||||||
|
app.bind(modes, k, act, &blk)
|
||||||
|
end
|
||||||
|
dsl.instance_exec(&block) if block_given?
|
||||||
|
elsif block_given?
|
||||||
|
keys = [keys] unless keys.is_a?(Array)
|
||||||
|
modes.each do |mode|
|
||||||
|
keys.each do |key|
|
||||||
|
@key_handlers[mode] ||= {}
|
||||||
|
@key_handlers[mode][key] ||= []
|
||||||
|
@key_handlers[mode][key] << block
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elsif action.is_a?(String)
|
||||||
|
keys = [keys] unless keys.is_a?(Array)
|
||||||
|
modes.each do |mode|
|
||||||
|
keys.each do |key|
|
||||||
|
@key_binds[mode] ||= {}
|
||||||
|
@key_binds[mode][key] ||= []
|
||||||
|
@key_binds[mode][key] << action
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
611
include/scripting/ruby_compiled.h
Normal file
611
include/scripting/ruby_compiled.h
Normal file
@@ -0,0 +1,611 @@
|
|||||||
|
#pragma once
|
||||||
|
constexpr unsigned char _tmp___crib_precompiled_mrb[] = {
|
||||||
|
0x52, 0x49, 0x54, 0x45, 0x30, 0x33, 0x30, 0x30, 0x00, 0x00, 0x1c, 0x69,
|
||||||
|
0x4d, 0x41, 0x54, 0x5a, 0x30, 0x30, 0x30, 0x30, 0x49, 0x52, 0x45, 0x50,
|
||||||
|
0x00, 0x00, 0x1b, 0x81, 0x30, 0x33, 0x30, 0x30, 0x00, 0x00, 0x00, 0x34,
|
||||||
|
0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
|
||||||
|
0x11, 0x01, 0x5d, 0x01, 0x00, 0x5e, 0x01, 0x00, 0x11, 0x01, 0x5d, 0x01,
|
||||||
|
0x01, 0x5e, 0x01, 0x01, 0x38, 0x01, 0x69, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||||
|
0x06, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x00, 0x00, 0x01, 0x43, 0x00,
|
||||||
|
0x00, 0x00, 0x03, 0xfd, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x01, 0x3c, 0x06, 0x01, 0x1e, 0x01, 0x00, 0x07, 0x01, 0x1e,
|
||||||
|
0x01, 0x01, 0x08, 0x01, 0x1e, 0x01, 0x02, 0x09, 0x01, 0x1e, 0x01, 0x03,
|
||||||
|
0x0a, 0x01, 0x1e, 0x01, 0x04, 0x0b, 0x01, 0x1e, 0x01, 0x05, 0x0c, 0x01,
|
||||||
|
0x1e, 0x01, 0x06, 0x0d, 0x01, 0x1e, 0x01, 0x07, 0x03, 0x01, 0x08, 0x1e,
|
||||||
|
0x01, 0x08, 0x03, 0x01, 0x09, 0x1e, 0x01, 0x09, 0x03, 0x01, 0x0a, 0x1e,
|
||||||
|
0x01, 0x0a, 0x03, 0x01, 0x0b, 0x1e, 0x01, 0x0b, 0x03, 0x01, 0x0c, 0x1e,
|
||||||
|
0x01, 0x0c, 0x03, 0x01, 0x0d, 0x1e, 0x01, 0x0d, 0x03, 0x01, 0x0e, 0x1e,
|
||||||
|
0x01, 0x0e, 0x03, 0x01, 0x0f, 0x1e, 0x01, 0x0f, 0x03, 0x01, 0x10, 0x1e,
|
||||||
|
0x01, 0x10, 0x03, 0x01, 0x11, 0x1e, 0x01, 0x11, 0x03, 0x01, 0x12, 0x1e,
|
||||||
|
0x01, 0x12, 0x03, 0x01, 0x13, 0x1e, 0x01, 0x13, 0x03, 0x01, 0x14, 0x1e,
|
||||||
|
0x01, 0x14, 0x03, 0x01, 0x15, 0x1e, 0x01, 0x15, 0x03, 0x01, 0x16, 0x1e,
|
||||||
|
0x01, 0x16, 0x03, 0x01, 0x17, 0x1e, 0x01, 0x17, 0x03, 0x01, 0x18, 0x1e,
|
||||||
|
0x01, 0x18, 0x03, 0x01, 0x19, 0x1e, 0x01, 0x19, 0x03, 0x01, 0x1a, 0x1e,
|
||||||
|
0x01, 0x1a, 0x03, 0x01, 0x1b, 0x1e, 0x01, 0x1b, 0x03, 0x01, 0x1c, 0x1e,
|
||||||
|
0x01, 0x1c, 0x03, 0x01, 0x1d, 0x1e, 0x01, 0x1d, 0x03, 0x01, 0x1e, 0x1e,
|
||||||
|
0x01, 0x1e, 0x03, 0x01, 0x1f, 0x1e, 0x01, 0x1f, 0x03, 0x01, 0x20, 0x1e,
|
||||||
|
0x01, 0x20, 0x03, 0x01, 0x21, 0x1e, 0x01, 0x21, 0x03, 0x01, 0x22, 0x1e,
|
||||||
|
0x01, 0x22, 0x03, 0x01, 0x23, 0x1e, 0x01, 0x23, 0x03, 0x01, 0x24, 0x1e,
|
||||||
|
0x01, 0x24, 0x03, 0x01, 0x25, 0x1e, 0x01, 0x25, 0x03, 0x01, 0x26, 0x1e,
|
||||||
|
0x01, 0x26, 0x03, 0x01, 0x27, 0x1e, 0x01, 0x27, 0x03, 0x01, 0x28, 0x1e,
|
||||||
|
0x01, 0x28, 0x03, 0x01, 0x29, 0x1e, 0x01, 0x29, 0x03, 0x01, 0x2a, 0x1e,
|
||||||
|
0x01, 0x2a, 0x03, 0x01, 0x2b, 0x1e, 0x01, 0x2b, 0x03, 0x01, 0x2c, 0x1e,
|
||||||
|
0x01, 0x2c, 0x03, 0x01, 0x2d, 0x1e, 0x01, 0x2d, 0x03, 0x01, 0x2e, 0x1e,
|
||||||
|
0x01, 0x2e, 0x03, 0x01, 0x2f, 0x1e, 0x01, 0x2f, 0x03, 0x01, 0x30, 0x1e,
|
||||||
|
0x01, 0x30, 0x03, 0x01, 0x31, 0x1e, 0x01, 0x31, 0x03, 0x01, 0x32, 0x1e,
|
||||||
|
0x01, 0x32, 0x03, 0x01, 0x33, 0x1e, 0x01, 0x33, 0x03, 0x01, 0x34, 0x1e,
|
||||||
|
0x01, 0x34, 0x2d, 0x01, 0x35, 0x00, 0x38, 0x01, 0x00, 0x00, 0x00, 0x36,
|
||||||
|
0x00, 0x06, 0x4b, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x00, 0x00, 0x09, 0x4b,
|
||||||
|
0x5f, 0x53, 0x48, 0x45, 0x42, 0x41, 0x4e, 0x47, 0x00, 0x00, 0x09, 0x4b,
|
||||||
|
0x5f, 0x43, 0x4f, 0x4d, 0x4d, 0x45, 0x4e, 0x54, 0x00, 0x00, 0x07, 0x4b,
|
||||||
|
0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x53,
|
||||||
|
0x54, 0x52, 0x49, 0x4e, 0x47, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x45, 0x53,
|
||||||
|
0x43, 0x41, 0x50, 0x45, 0x00, 0x00, 0x0f, 0x4b, 0x5f, 0x49, 0x4e, 0x54,
|
||||||
|
0x45, 0x52, 0x50, 0x4f, 0x4c, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x00,
|
||||||
|
0x08, 0x4b, 0x5f, 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x00, 0x00, 0x08,
|
||||||
|
0x4b, 0x5f, 0x4e, 0x55, 0x4d, 0x42, 0x45, 0x52, 0x00, 0x00, 0x06, 0x4b,
|
||||||
|
0x5f, 0x54, 0x52, 0x55, 0x45, 0x00, 0x00, 0x07, 0x4b, 0x5f, 0x46, 0x41,
|
||||||
|
0x4c, 0x53, 0x45, 0x00, 0x00, 0x06, 0x4b, 0x5f, 0x43, 0x48, 0x41, 0x52,
|
||||||
|
0x00, 0x00, 0x09, 0x4b, 0x5f, 0x4b, 0x45, 0x59, 0x57, 0x4f, 0x52, 0x44,
|
||||||
|
0x00, 0x00, 0x11, 0x4b, 0x5f, 0x4b, 0x45, 0x59, 0x57, 0x4f, 0x52, 0x44,
|
||||||
|
0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x4f, 0x52, 0x00, 0x00, 0x0a, 0x4b,
|
||||||
|
0x5f, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x4f, 0x52, 0x00, 0x00, 0x0a,
|
||||||
|
0x4b, 0x5f, 0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x00,
|
||||||
|
0x06, 0x4b, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x00, 0x00, 0x0a, 0x4b, 0x5f,
|
||||||
|
0x43, 0x4f, 0x4e, 0x53, 0x54, 0x41, 0x4e, 0x54, 0x00, 0x00, 0x12, 0x4b,
|
||||||
|
0x5f, 0x56, 0x41, 0x52, 0x49, 0x41, 0x42, 0x4c, 0x45, 0x49, 0x4e, 0x53,
|
||||||
|
0x54, 0x41, 0x4e, 0x43, 0x45, 0x00, 0x00, 0x10, 0x4b, 0x5f, 0x56, 0x41,
|
||||||
|
0x52, 0x49, 0x41, 0x42, 0x4c, 0x45, 0x47, 0x4c, 0x4f, 0x42, 0x41, 0x4c,
|
||||||
|
0x00, 0x00, 0x0c, 0x4b, 0x5f, 0x41, 0x4e, 0x4e, 0x4f, 0x54, 0x41, 0x54,
|
||||||
|
0x49, 0x4f, 0x4e, 0x00, 0x00, 0x0b, 0x4b, 0x5f, 0x44, 0x49, 0x52, 0x45,
|
||||||
|
0x43, 0x54, 0x49, 0x56, 0x45, 0x00, 0x00, 0x07, 0x4b, 0x5f, 0x4c, 0x41,
|
||||||
|
0x42, 0x45, 0x4c, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43,
|
||||||
|
0x45, 0x31, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43, 0x45,
|
||||||
|
0x32, 0x00, 0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43, 0x45, 0x33,
|
||||||
|
0x00, 0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43, 0x45, 0x34, 0x00,
|
||||||
|
0x00, 0x08, 0x4b, 0x5f, 0x42, 0x52, 0x41, 0x43, 0x45, 0x35, 0x00, 0x00,
|
||||||
|
0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49, 0x4e, 0x47, 0x31, 0x00,
|
||||||
|
0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49, 0x4e, 0x47, 0x32,
|
||||||
|
0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49, 0x4e, 0x47,
|
||||||
|
0x33, 0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49, 0x4e,
|
||||||
|
0x47, 0x34, 0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44, 0x49,
|
||||||
|
0x4e, 0x47, 0x35, 0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x48, 0x45, 0x41, 0x44,
|
||||||
|
0x49, 0x4e, 0x47, 0x36, 0x00, 0x00, 0x0c, 0x4b, 0x5f, 0x42, 0x4c, 0x4f,
|
||||||
|
0x43, 0x4b, 0x51, 0x55, 0x4f, 0x54, 0x45, 0x00, 0x00, 0x06, 0x4b, 0x5f,
|
||||||
|
0x4c, 0x49, 0x53, 0x54, 0x00, 0x00, 0x0a, 0x4b, 0x5f, 0x4c, 0x49, 0x53,
|
||||||
|
0x54, 0x49, 0x54, 0x45, 0x4d, 0x00, 0x00, 0x06, 0x4b, 0x5f, 0x43, 0x4f,
|
||||||
|
0x44, 0x45, 0x00, 0x00, 0x0e, 0x4b, 0x5f, 0x4c, 0x41, 0x4e, 0x47, 0x55,
|
||||||
|
0x41, 0x47, 0x45, 0x4e, 0x41, 0x4d, 0x45, 0x00, 0x00, 0x0b, 0x4b, 0x5f,
|
||||||
|
0x4c, 0x49, 0x4e, 0x4b, 0x4c, 0x41, 0x42, 0x45, 0x4c, 0x00, 0x00, 0x0c,
|
||||||
|
0x4b, 0x5f, 0x49, 0x4d, 0x41, 0x47, 0x45, 0x4c, 0x41, 0x42, 0x45, 0x4c,
|
||||||
|
0x00, 0x00, 0x06, 0x4b, 0x5f, 0x4c, 0x49, 0x4e, 0x4b, 0x00, 0x00, 0x07,
|
||||||
|
0x4b, 0x5f, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x00, 0x00, 0x0d, 0x4b, 0x5f,
|
||||||
|
0x54, 0x41, 0x42, 0x4c, 0x45, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x00,
|
||||||
|
0x00, 0x08, 0x4b, 0x5f, 0x49, 0x54, 0x41, 0x4c, 0x49, 0x43, 0x00, 0x00,
|
||||||
|
0x06, 0x4b, 0x5f, 0x42, 0x4f, 0x4c, 0x44, 0x00, 0x00, 0x0b, 0x4b, 0x5f,
|
||||||
|
0x55, 0x4e, 0x44, 0x45, 0x52, 0x4c, 0x49, 0x4e, 0x45, 0x00, 0x00, 0x0f,
|
||||||
|
0x4b, 0x5f, 0x53, 0x54, 0x52, 0x49, 0x4b, 0x45, 0x54, 0x48, 0x52, 0x4f,
|
||||||
|
0x55, 0x47, 0x48, 0x00, 0x00, 0x10, 0x4b, 0x5f, 0x48, 0x4f, 0x52, 0x49,
|
||||||
|
0x58, 0x4f, 0x4e, 0x54, 0x41, 0x4c, 0x52, 0x55, 0x4c, 0x45, 0x00, 0x00,
|
||||||
|
0x05, 0x4b, 0x5f, 0x54, 0x41, 0x47, 0x00, 0x00, 0x0b, 0x4b, 0x5f, 0x41,
|
||||||
|
0x54, 0x54, 0x52, 0x49, 0x42, 0x55, 0x54, 0x45, 0x00, 0x00, 0x0b, 0x4b,
|
||||||
|
0x5f, 0x43, 0x48, 0x45, 0x43, 0x4b, 0x44, 0x4f, 0x4e, 0x45, 0x00, 0x00,
|
||||||
|
0x0e, 0x4b, 0x5f, 0x43, 0x48, 0x45, 0x43, 0x4b, 0x4e, 0x4f, 0x54, 0x44,
|
||||||
|
0x4f, 0x4e, 0x45, 0x00, 0x00, 0x06, 0x66, 0x72, 0x65, 0x65, 0x7a, 0x65,
|
||||||
|
0x00, 0x00, 0x00, 0x0f, 0x61, 0x00, 0x01, 0x00, 0x4c, 0x00, 0x02, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x07, 0x6f, 0x51, 0x01, 0x00, 0x51, 0x02, 0x01, 0x51,
|
||||||
|
0x03, 0x02, 0x51, 0x04, 0x03, 0x51, 0x05, 0x04, 0x51, 0x06, 0x05, 0x51,
|
||||||
|
0x07, 0x06, 0x51, 0x08, 0x07, 0x47, 0x02, 0x07, 0x51, 0x03, 0x08, 0x47,
|
||||||
|
0x04, 0x00, 0x51, 0x05, 0x09, 0x51, 0x06, 0x0a, 0x47, 0x06, 0x01, 0x51,
|
||||||
|
0x07, 0x0b, 0x51, 0x08, 0x0c, 0x47, 0x08, 0x01, 0x51, 0x09, 0x0d, 0x51,
|
||||||
|
0x0a, 0x0e, 0x47, 0x0a, 0x01, 0x51, 0x0b, 0x0f, 0x51, 0x0c, 0x0e, 0x47,
|
||||||
|
0x0c, 0x01, 0x51, 0x0d, 0x10, 0x51, 0x0e, 0x0c, 0x47, 0x0e, 0x01, 0x51,
|
||||||
|
0x0f, 0x11, 0x51, 0x10, 0x12, 0x47, 0x10, 0x01, 0x51, 0x11, 0x13, 0x51,
|
||||||
|
0x12, 0x14, 0x47, 0x12, 0x01, 0x51, 0x13, 0x15, 0x51, 0x14, 0x0e, 0x47,
|
||||||
|
0x14, 0x01, 0x51, 0x15, 0x16, 0x51, 0x16, 0x0e, 0x47, 0x16, 0x01, 0x51,
|
||||||
|
0x17, 0x17, 0x47, 0x18, 0x00, 0x51, 0x19, 0x18, 0x51, 0x1a, 0x0e, 0x47,
|
||||||
|
0x1a, 0x01, 0x51, 0x1b, 0x19, 0x47, 0x1c, 0x00, 0x51, 0x1d, 0x1a, 0x51,
|
||||||
|
0x1e, 0x0e, 0x47, 0x1e, 0x01, 0x51, 0x1f, 0x1b, 0x51, 0x20, 0x1c, 0x47,
|
||||||
|
0x20, 0x01, 0x51, 0x21, 0x1d, 0x47, 0x22, 0x00, 0x51, 0x23, 0x1e, 0x51,
|
||||||
|
0x24, 0x14, 0x51, 0x25, 0x0a, 0x47, 0x24, 0x02, 0x51, 0x25, 0x1f, 0x51,
|
||||||
|
0x26, 0x0e, 0x47, 0x26, 0x01, 0x51, 0x27, 0x20, 0x51, 0x28, 0x12, 0x47,
|
||||||
|
0x28, 0x01, 0x51, 0x29, 0x21, 0x47, 0x2a, 0x00, 0x51, 0x2b, 0x22, 0x51,
|
||||||
|
0x2c, 0x23, 0x51, 0x2d, 0x24, 0x51, 0x2e, 0x0a, 0x47, 0x2c, 0x03, 0x53,
|
||||||
|
0x01, 0x16, 0x1a, 0x01, 0x00, 0x10, 0x01, 0x01, 0x10, 0x02, 0x02, 0x0f,
|
||||||
|
0x03, 0x00, 0x55, 0x55, 0x55, 0x10, 0x04, 0x03, 0x51, 0x05, 0x25, 0x10,
|
||||||
|
0x06, 0x04, 0x51, 0x07, 0x26, 0x47, 0x07, 0x01, 0x10, 0x08, 0x05, 0x51,
|
||||||
|
0x09, 0x00, 0x53, 0x02, 0x04, 0x10, 0x03, 0x06, 0x10, 0x04, 0x02, 0x0e,
|
||||||
|
0x05, 0x59, 0x9c, 0x10, 0x06, 0x03, 0x51, 0x07, 0x27, 0x10, 0x08, 0x04,
|
||||||
|
0x51, 0x09, 0x28, 0x51, 0x0a, 0x29, 0x51, 0x0b, 0x2a, 0x47, 0x09, 0x03,
|
||||||
|
0x10, 0x0a, 0x05, 0x51, 0x0b, 0x00, 0x53, 0x04, 0x04, 0x10, 0x05, 0x07,
|
||||||
|
0x10, 0x06, 0x02, 0x0f, 0x07, 0x00, 0xa8, 0xb9, 0xcc, 0x10, 0x08, 0x03,
|
||||||
|
0x51, 0x09, 0x2b, 0x10, 0x0a, 0x04, 0x51, 0x0b, 0x2c, 0x51, 0x0c, 0x2d,
|
||||||
|
0x47, 0x0b, 0x02, 0x10, 0x0c, 0x05, 0x51, 0x0d, 0x00, 0x53, 0x06, 0x04,
|
||||||
|
0x10, 0x07, 0x08, 0x10, 0x08, 0x02, 0x0f, 0x09, 0x00, 0x36, 0xa3, 0xd9,
|
||||||
|
0x10, 0x0a, 0x03, 0x51, 0x0b, 0x2e, 0x10, 0x0c, 0x04, 0x51, 0x0d, 0x2f,
|
||||||
|
0x47, 0x0d, 0x01, 0x10, 0x0e, 0x05, 0x51, 0x0f, 0x0d, 0x53, 0x08, 0x04,
|
||||||
|
0x10, 0x09, 0x09, 0x10, 0x0a, 0x02, 0x0f, 0x0b, 0x00, 0x4d, 0x5a, 0x5e,
|
||||||
|
0x10, 0x0c, 0x03, 0x51, 0x0d, 0x30, 0x10, 0x0e, 0x04, 0x51, 0x0f, 0x31,
|
||||||
|
0x47, 0x0f, 0x01, 0x10, 0x10, 0x05, 0x51, 0x11, 0x10, 0x53, 0x0a, 0x04,
|
||||||
|
0x10, 0x0b, 0x0a, 0x10, 0x0c, 0x02, 0x0f, 0x0d, 0x00, 0x00, 0xad, 0xd8,
|
||||||
|
0x10, 0x0e, 0x03, 0x51, 0x0f, 0x32, 0x10, 0x10, 0x04, 0x51, 0x11, 0x33,
|
||||||
|
0x47, 0x11, 0x01, 0x10, 0x12, 0x05, 0x51, 0x13, 0x11, 0x53, 0x0c, 0x04,
|
||||||
|
0x10, 0x0d, 0x0b, 0x10, 0x0e, 0x02, 0x0f, 0x0f, 0x00, 0x00, 0xad, 0xd8,
|
||||||
|
0x10, 0x10, 0x03, 0x51, 0x11, 0x32, 0x10, 0x12, 0x04, 0x51, 0x13, 0x34,
|
||||||
|
0x47, 0x13, 0x01, 0x10, 0x14, 0x05, 0x51, 0x15, 0x11, 0x53, 0x0e, 0x04,
|
||||||
|
0x10, 0x0f, 0x0c, 0x10, 0x10, 0x02, 0x0f, 0x11, 0x00, 0xa0, 0x74, 0xc4,
|
||||||
|
0x10, 0x12, 0x03, 0x51, 0x13, 0x35, 0x10, 0x14, 0x04, 0x51, 0x15, 0x36,
|
||||||
|
0x51, 0x16, 0x37, 0x47, 0x15, 0x02, 0x10, 0x16, 0x05, 0x51, 0x17, 0x13,
|
||||||
|
0x53, 0x10, 0x04, 0x10, 0x11, 0x0d, 0x10, 0x12, 0x02, 0x0f, 0x13, 0x00,
|
||||||
|
0xef, 0x8a, 0x91, 0x10, 0x14, 0x03, 0x51, 0x15, 0x38, 0x10, 0x16, 0x04,
|
||||||
|
0x51, 0x17, 0x39, 0x51, 0x18, 0x3a, 0x47, 0x17, 0x02, 0x10, 0x18, 0x05,
|
||||||
|
0x51, 0x19, 0x15, 0x53, 0x12, 0x04, 0x10, 0x13, 0x0e, 0x10, 0x14, 0x02,
|
||||||
|
0x0f, 0x15, 0x00, 0xf0, 0xdf, 0x8a, 0x10, 0x16, 0x03, 0x51, 0x17, 0x3b,
|
||||||
|
0x10, 0x18, 0x04, 0x51, 0x19, 0x3c, 0x47, 0x19, 0x01, 0x10, 0x1a, 0x05,
|
||||||
|
0x51, 0x1b, 0x16, 0x53, 0x14, 0x04, 0x10, 0x15, 0x0f, 0x10, 0x16, 0x02,
|
||||||
|
0x0f, 0x17, 0x00, 0x36, 0xa3, 0xd9, 0x10, 0x18, 0x03, 0x51, 0x19, 0x3d,
|
||||||
|
0x10, 0x1a, 0x04, 0x51, 0x1b, 0x3e, 0x47, 0x1b, 0x01, 0x10, 0x1c, 0x05,
|
||||||
|
0x51, 0x1d, 0x16, 0x53, 0x16, 0x04, 0x10, 0x17, 0x10, 0x10, 0x18, 0x02,
|
||||||
|
0x0f, 0x19, 0x00, 0xcb, 0xcb, 0x41, 0x10, 0x1a, 0x03, 0x51, 0x1b, 0x3f,
|
||||||
|
0x10, 0x1c, 0x04, 0x51, 0x1d, 0x40, 0x47, 0x1d, 0x01, 0x10, 0x1e, 0x05,
|
||||||
|
0x51, 0x1f, 0x0f, 0x53, 0x18, 0x04, 0x10, 0x19, 0x11, 0x10, 0x1a, 0x02,
|
||||||
|
0x0f, 0x1b, 0x00, 0xcb, 0xcb, 0x41, 0x10, 0x1c, 0x03, 0x51, 0x1d, 0x3f,
|
||||||
|
0x10, 0x1e, 0x04, 0x51, 0x1f, 0x41, 0x47, 0x1f, 0x01, 0x10, 0x20, 0x05,
|
||||||
|
0x51, 0x21, 0x0f, 0x53, 0x1a, 0x04, 0x10, 0x1b, 0x12, 0x10, 0x1c, 0x02,
|
||||||
|
0x0f, 0x1d, 0x00, 0x6e, 0x15, 0x16, 0x10, 0x1e, 0x03, 0x51, 0x1f, 0x38,
|
||||||
|
0x10, 0x20, 0x04, 0x51, 0x21, 0x42, 0x47, 0x21, 0x01, 0x10, 0x22, 0x05,
|
||||||
|
0x51, 0x23, 0x08, 0x53, 0x1c, 0x04, 0x10, 0x1d, 0x13, 0x10, 0x1e, 0x02,
|
||||||
|
0x0f, 0x1f, 0x00, 0x36, 0xa3, 0xd9, 0x10, 0x20, 0x03, 0x51, 0x21, 0x43,
|
||||||
|
0x10, 0x22, 0x04, 0x51, 0x23, 0x44, 0x47, 0x23, 0x01, 0x10, 0x24, 0x05,
|
||||||
|
0x51, 0x25, 0x17, 0x53, 0x1e, 0x04, 0x10, 0x1f, 0x14, 0x10, 0x20, 0x02,
|
||||||
|
0x0f, 0x21, 0x00, 0x95, 0xe6, 0xcb, 0x10, 0x22, 0x03, 0x51, 0x23, 0x45,
|
||||||
|
0x10, 0x24, 0x04, 0x51, 0x25, 0x46, 0x47, 0x25, 0x01, 0x10, 0x26, 0x05,
|
||||||
|
0x51, 0x27, 0x47, 0x53, 0x20, 0x04, 0x10, 0x21, 0x15, 0x10, 0x22, 0x02,
|
||||||
|
0x0f, 0x23, 0x00, 0xde, 0xa5, 0x84, 0x10, 0x24, 0x03, 0x51, 0x25, 0x48,
|
||||||
|
0x10, 0x26, 0x04, 0x51, 0x27, 0x49, 0x47, 0x27, 0x01, 0x10, 0x28, 0x05,
|
||||||
|
0x51, 0x29, 0x19, 0x53, 0x22, 0x04, 0x10, 0x23, 0x16, 0x10, 0x24, 0x02,
|
||||||
|
0x0f, 0x25, 0x00, 0xa0, 0x74, 0xc4, 0x10, 0x26, 0x03, 0x51, 0x27, 0x4a,
|
||||||
|
0x10, 0x28, 0x04, 0x51, 0x29, 0x4b, 0x47, 0x29, 0x01, 0x10, 0x2a, 0x05,
|
||||||
|
0x51, 0x2b, 0x1a, 0x53, 0x24, 0x04, 0x10, 0x25, 0x17, 0x10, 0x26, 0x02,
|
||||||
|
0x0f, 0x27, 0x00, 0x36, 0xa3, 0xd9, 0x10, 0x28, 0x03, 0x51, 0x29, 0x4c,
|
||||||
|
0x10, 0x2a, 0x04, 0x51, 0x2b, 0x4d, 0x51, 0x2c, 0x4e, 0x47, 0x2b, 0x02,
|
||||||
|
0x10, 0x2c, 0x05, 0x51, 0x2d, 0x1b, 0x53, 0x26, 0x04, 0x10, 0x27, 0x18,
|
||||||
|
0x10, 0x28, 0x02, 0x0f, 0x29, 0x00, 0x6d, 0x80, 0x86, 0x10, 0x2a, 0x03,
|
||||||
|
0x51, 0x2b, 0x4f, 0x10, 0x2c, 0x04, 0x51, 0x2d, 0x50, 0x47, 0x2d, 0x01,
|
||||||
|
0x10, 0x2e, 0x05, 0x51, 0x2f, 0x1d, 0x53, 0x28, 0x04, 0x10, 0x29, 0x19,
|
||||||
|
0x10, 0x2a, 0x02, 0x0f, 0x2b, 0x00, 0x36, 0xa3, 0xd9, 0x10, 0x2c, 0x03,
|
||||||
|
0x51, 0x2d, 0x51, 0x10, 0x2e, 0x04, 0x51, 0x2f, 0x52, 0x47, 0x2f, 0x01,
|
||||||
|
0x10, 0x30, 0x05, 0x51, 0x31, 0x1e, 0x53, 0x2a, 0x04, 0x10, 0x2b, 0x1a,
|
||||||
|
0x10, 0x2c, 0x02, 0x0f, 0x2d, 0x00, 0x6d, 0x80, 0x86, 0x10, 0x2e, 0x03,
|
||||||
|
0x51, 0x2f, 0x4f, 0x10, 0x30, 0x04, 0x51, 0x31, 0x53, 0x51, 0x32, 0x54,
|
||||||
|
0x47, 0x31, 0x02, 0x10, 0x32, 0x05, 0x51, 0x33, 0x1f, 0x53, 0x2c, 0x04,
|
||||||
|
0x10, 0x2d, 0x1b, 0x10, 0x2e, 0x02, 0x0f, 0x2f, 0x00, 0xda, 0xd8, 0xd8,
|
||||||
|
0x10, 0x30, 0x03, 0x51, 0x31, 0x55, 0x10, 0x32, 0x04, 0x51, 0x33, 0x56,
|
||||||
|
0x47, 0x33, 0x01, 0x10, 0x34, 0x05, 0x51, 0x35, 0x20, 0x53, 0x2e, 0x04,
|
||||||
|
0x10, 0x2f, 0x1c, 0x10, 0x30, 0x02, 0x0f, 0x31, 0x00, 0x4e, 0x5c, 0x61,
|
||||||
|
0x10, 0x32, 0x03, 0x51, 0x33, 0x57, 0x10, 0x34, 0x04, 0x51, 0x35, 0x58,
|
||||||
|
0x51, 0x36, 0x59, 0x47, 0x35, 0x02, 0x10, 0x36, 0x05, 0x51, 0x37, 0x21,
|
||||||
|
0x53, 0x30, 0x04, 0x10, 0x31, 0x1d, 0x10, 0x32, 0x02, 0x0f, 0x33, 0x00,
|
||||||
|
0x6d, 0x80, 0x86, 0x10, 0x34, 0x03, 0x51, 0x35, 0x5a, 0x10, 0x36, 0x04,
|
||||||
|
0x51, 0x37, 0x5b, 0x47, 0x37, 0x01, 0x53, 0x32, 0x03, 0x10, 0x33, 0x1e,
|
||||||
|
0x10, 0x34, 0x02, 0x0f, 0x35, 0x00, 0xda, 0xd8, 0xd8, 0x10, 0x36, 0x03,
|
||||||
|
0x51, 0x37, 0x5c, 0x10, 0x38, 0x04, 0x51, 0x39, 0x5d, 0x47, 0x39, 0x01,
|
||||||
|
0x53, 0x34, 0x03, 0x10, 0x35, 0x1f, 0x10, 0x36, 0x02, 0x0f, 0x37, 0x00,
|
||||||
|
0xdd, 0x4c, 0x35, 0x10, 0x38, 0x03, 0x51, 0x39, 0x5e, 0x10, 0x3a, 0x04,
|
||||||
|
0x51, 0x3b, 0x5f, 0x51, 0x3c, 0x60, 0x47, 0x3b, 0x02, 0x53, 0x36, 0x03,
|
||||||
|
0x10, 0x37, 0x20, 0x10, 0x38, 0x02, 0x0f, 0x39, 0x00, 0xf0, 0x50, 0x32,
|
||||||
|
0x10, 0x3a, 0x03, 0x51, 0x3b, 0x61, 0x10, 0x3c, 0x04, 0x51, 0x3d, 0x62,
|
||||||
|
0x47, 0x3d, 0x01, 0x53, 0x38, 0x03, 0x10, 0x39, 0x21, 0x10, 0x3a, 0x02,
|
||||||
|
0x0f, 0x3b, 0x00, 0xf0, 0x50, 0x32, 0x10, 0x3c, 0x03, 0x51, 0x3d, 0x61,
|
||||||
|
0x10, 0x3e, 0x04, 0x51, 0x3f, 0x63, 0x47, 0x3f, 0x01, 0x53, 0x3a, 0x03,
|
||||||
|
0x10, 0x3b, 0x22, 0x10, 0x3c, 0x02, 0x0f, 0x3d, 0x00, 0x9e, 0x9e, 0x9e,
|
||||||
|
0x10, 0x3e, 0x03, 0x51, 0x3f, 0x64, 0x10, 0x40, 0x04, 0x51, 0x41, 0x65,
|
||||||
|
0x47, 0x41, 0x01, 0x53, 0x3c, 0x03, 0x10, 0x3d, 0x23, 0x10, 0x3e, 0x02,
|
||||||
|
0x0f, 0x3f, 0x00, 0x6d, 0x80, 0x86, 0x10, 0x40, 0x03, 0x51, 0x41, 0x4f,
|
||||||
|
0x10, 0x42, 0x04, 0x51, 0x43, 0x66, 0x47, 0x43, 0x01, 0x53, 0x3e, 0x03,
|
||||||
|
0x10, 0x3f, 0x24, 0x10, 0x40, 0x02, 0x0f, 0x41, 0x00, 0xff, 0x80, 0x87,
|
||||||
|
0x10, 0x42, 0x03, 0x51, 0x43, 0x67, 0x10, 0x44, 0x04, 0x51, 0x45, 0x68,
|
||||||
|
0x47, 0x45, 0x01, 0x10, 0x46, 0x25, 0x51, 0x47, 0x69, 0x47, 0x47, 0x01,
|
||||||
|
0x10, 0x48, 0x05, 0x51, 0x49, 0x09, 0x53, 0x40, 0x05, 0x10, 0x41, 0x26,
|
||||||
|
0x10, 0x42, 0x02, 0x0f, 0x43, 0x00, 0x4d, 0x5a, 0x5e, 0x10, 0x44, 0x03,
|
||||||
|
0x51, 0x45, 0x6a, 0x10, 0x46, 0x04, 0x51, 0x47, 0x6b, 0x47, 0x47, 0x01,
|
||||||
|
0x10, 0x48, 0x25, 0x51, 0x49, 0x6c, 0x51, 0x4a, 0x6d, 0x47, 0x49, 0x02,
|
||||||
|
0x10, 0x4a, 0x05, 0x51, 0x4b, 0x0b, 0x53, 0x42, 0x05, 0x53, 0x01, 0x21,
|
||||||
|
0x1a, 0x01, 0x27, 0x10, 0x01, 0x28, 0x10, 0x02, 0x29, 0x0f, 0x03, 0x00,
|
||||||
|
0xee, 0xee, 0xee, 0x53, 0x02, 0x01, 0x10, 0x03, 0x2a, 0x10, 0x04, 0x29,
|
||||||
|
0x0f, 0x05, 0x00, 0x7d, 0xcf, 0xff, 0x53, 0x04, 0x01, 0x10, 0x05, 0x2b,
|
||||||
|
0x10, 0x06, 0x29, 0x0f, 0x07, 0x00, 0xef, 0x51, 0x68, 0x53, 0x06, 0x01,
|
||||||
|
0x10, 0x07, 0x2c, 0x10, 0x08, 0x29, 0x0f, 0x09, 0x00, 0xaa, 0xaa, 0xaa,
|
||||||
|
0x10, 0x0a, 0x2d, 0x13, 0x0b, 0x53, 0x08, 0x02, 0x10, 0x09, 0x2e, 0x10,
|
||||||
|
0x0a, 0x29, 0x0f, 0x0b, 0x00, 0xaa, 0xd9, 0x4c, 0x53, 0x0a, 0x01, 0x10,
|
||||||
|
0x0b, 0x2f, 0x10, 0x0c, 0x29, 0x0f, 0x0d, 0x00, 0x7d, 0xcf, 0xff, 0x53,
|
||||||
|
0x0c, 0x01, 0x10, 0x0d, 0x30, 0x10, 0x0e, 0x29, 0x0f, 0x0f, 0x00, 0x7d,
|
||||||
|
0xcf, 0xff, 0x53, 0x0e, 0x01, 0x10, 0x0f, 0x31, 0x10, 0x10, 0x29, 0x0f,
|
||||||
|
0x11, 0x00, 0xd2, 0xa6, 0xff, 0x53, 0x10, 0x01, 0x10, 0x11, 0x32, 0x10,
|
||||||
|
0x12, 0x29, 0x0f, 0x13, 0x00, 0xe6, 0xc0, 0x8a, 0x53, 0x12, 0x01, 0x10,
|
||||||
|
0x13, 0x33, 0x10, 0x14, 0x29, 0x0f, 0x15, 0x00, 0x7a, 0xe9, 0x3c, 0x53,
|
||||||
|
0x14, 0x01, 0x10, 0x15, 0x34, 0x10, 0x16, 0x29, 0x0f, 0x17, 0x00, 0xef,
|
||||||
|
0x51, 0x68, 0x53, 0x16, 0x01, 0x10, 0x17, 0x35, 0x10, 0x18, 0x29, 0x0f,
|
||||||
|
0x19, 0x00, 0xff, 0xaf, 0x70, 0x53, 0x18, 0x01, 0x10, 0x19, 0x36, 0x10,
|
||||||
|
0x1a, 0x29, 0x0f, 0x1b, 0x00, 0xff, 0x8f, 0x40, 0x53, 0x1a, 0x01, 0x10,
|
||||||
|
0x1b, 0x37, 0x10, 0x1c, 0x29, 0x0f, 0x1d, 0x00, 0xf0, 0x71, 0x78, 0x53,
|
||||||
|
0x1c, 0x01, 0x10, 0x1d, 0x38, 0x10, 0x1e, 0x29, 0x0f, 0x1f, 0x00, 0xff,
|
||||||
|
0xff, 0xff, 0x10, 0x20, 0x2d, 0x13, 0x21, 0x53, 0x1e, 0x02, 0x10, 0x1f,
|
||||||
|
0x39, 0x10, 0x20, 0x29, 0x0f, 0x21, 0x00, 0xff, 0xaf, 0x70, 0x53, 0x20,
|
||||||
|
0x01, 0x10, 0x21, 0x3a, 0x10, 0x22, 0x29, 0x0f, 0x23, 0x00, 0xf0, 0x71,
|
||||||
|
0x78, 0x53, 0x22, 0x01, 0x10, 0x23, 0x3b, 0x10, 0x24, 0x29, 0x0f, 0x25,
|
||||||
|
0x00, 0x7d, 0xcf, 0xff, 0x53, 0x24, 0x01, 0x10, 0x25, 0x3c, 0x10, 0x26,
|
||||||
|
0x29, 0x0f, 0x27, 0x00, 0x95, 0xe6, 0xcb, 0x53, 0x26, 0x01, 0x10, 0x27,
|
||||||
|
0x3d, 0x10, 0x28, 0x29, 0x0f, 0x29, 0x00, 0xf0, 0x71, 0x78, 0x53, 0x28,
|
||||||
|
0x01, 0x10, 0x29, 0x3e, 0x10, 0x2a, 0x29, 0x0f, 0x2b, 0x00, 0x7d, 0xcf,
|
||||||
|
0xff, 0x53, 0x2a, 0x01, 0x10, 0x2b, 0x3f, 0x10, 0x2c, 0x29, 0x0f, 0x2d,
|
||||||
|
0x00, 0xff, 0x8f, 0x40, 0x53, 0x2c, 0x01, 0x10, 0x2d, 0x40, 0x10, 0x2e,
|
||||||
|
0x29, 0x0f, 0x2f, 0x00, 0xd2, 0xa6, 0xff, 0x53, 0x2e, 0x01, 0x10, 0x2f,
|
||||||
|
0x41, 0x10, 0x30, 0x29, 0x0f, 0x31, 0x00, 0xd2, 0xa6, 0xff, 0x53, 0x30,
|
||||||
|
0x01, 0x10, 0x31, 0x42, 0x10, 0x32, 0x29, 0x0f, 0x33, 0x00, 0xff, 0xaf,
|
||||||
|
0xaf, 0x53, 0x32, 0x01, 0x10, 0x33, 0x43, 0x10, 0x34, 0x29, 0x0f, 0x35,
|
||||||
|
0x00, 0xff, 0xff, 0x00, 0x53, 0x34, 0x01, 0x10, 0x35, 0x44, 0x10, 0x36,
|
||||||
|
0x29, 0x0f, 0x37, 0x00, 0x0f, 0xff, 0x0f, 0x53, 0x36, 0x01, 0x10, 0x37,
|
||||||
|
0x45, 0x10, 0x38, 0x29, 0x0f, 0x39, 0x00, 0xff, 0x0f, 0x0f, 0x53, 0x38,
|
||||||
|
0x01, 0x53, 0x01, 0x1c, 0x1a, 0x01, 0x46, 0x10, 0x01, 0x47, 0x1a, 0x01,
|
||||||
|
0x48, 0x53, 0x01, 0x00, 0x1a, 0x01, 0x49, 0x53, 0x01, 0x00, 0x1a, 0x01,
|
||||||
|
0x4a, 0x53, 0x01, 0x00, 0x1a, 0x01, 0x4b, 0x11, 0x01, 0x1a, 0x01, 0x4c,
|
||||||
|
0x11, 0x01, 0x1a, 0x01, 0x4d, 0x57, 0x02, 0x00, 0x2e, 0x01, 0x4e, 0x00,
|
||||||
|
0x1a, 0x01, 0x4f, 0x12, 0x01, 0x62, 0x01, 0x5e, 0x01, 0x01, 0x38, 0x01,
|
||||||
|
0x00, 0x6e, 0x00, 0x00, 0x06, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x64, 0x00,
|
||||||
|
0x00, 0x00, 0x12, 0x2d, 0x2d, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f,
|
||||||
|
0x75, 0x6e, 0x64, 0x2d, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x00, 0x00, 0x00,
|
||||||
|
0x0c, 0x2d, 0x2d, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x74, 0x69, 0x64,
|
||||||
|
0x79, 0x00, 0x00, 0x00, 0x1b, 0x2d, 0x2d, 0x63, 0x6f, 0x6d, 0x70, 0x6c,
|
||||||
|
0x65, 0x74, 0x69, 0x6f, 0x6e, 0x2d, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3d,
|
||||||
|
0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x00, 0x00, 0x00, 0x18,
|
||||||
|
0x2d, 0x2d, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x2d, 0x69, 0x6e, 0x73,
|
||||||
|
0x65, 0x72, 0x74, 0x69, 0x6f, 0x6e, 0x3d, 0x6e, 0x65, 0x76, 0x65, 0x72,
|
||||||
|
0x00, 0x00, 0x00, 0x14, 0x2d, 0x2d, 0x70, 0x63, 0x68, 0x2d, 0x73, 0x74,
|
||||||
|
0x6f, 0x72, 0x61, 0x67, 0x65, 0x3d, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79,
|
||||||
|
0x00, 0x00, 0x00, 0x12, 0x2d, 0x2d, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x2d,
|
||||||
|
0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x3d, 0x35, 0x30, 0x00, 0x00,
|
||||||
|
0x00, 0x0b, 0x2d, 0x2d, 0x6c, 0x6f, 0x67, 0x3d, 0x65, 0x72, 0x72, 0x6f,
|
||||||
|
0x72, 0x00, 0x00, 0x00, 0x08, 0x72, 0x75, 0x62, 0x79, 0x2d, 0x6c, 0x73,
|
||||||
|
0x70, 0x00, 0x00, 0x00, 0x0a, 0x73, 0x6f, 0x6c, 0x61, 0x72, 0x67, 0x72,
|
||||||
|
0x61, 0x70, 0x68, 0x00, 0x00, 0x00, 0x05, 0x73, 0x74, 0x64, 0x69, 0x6f,
|
||||||
|
0x00, 0x00, 0x00, 0x14, 0x62, 0x61, 0x73, 0x68, 0x2d, 0x6c, 0x61, 0x6e,
|
||||||
|
0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
|
||||||
|
0x00, 0x00, 0x00, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x00, 0x00,
|
||||||
|
0x1a, 0x76, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x63, 0x73, 0x73, 0x2d,
|
||||||
|
0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72,
|
||||||
|
0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x07, 0x2d, 0x2d, 0x73, 0x74, 0x64,
|
||||||
|
0x69, 0x6f, 0x00, 0x00, 0x00, 0x1b, 0x76, 0x73, 0x63, 0x6f, 0x64, 0x65,
|
||||||
|
0x2d, 0x6a, 0x73, 0x6f, 0x6e, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61,
|
||||||
|
0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00,
|
||||||
|
0x08, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x6c, 0x73, 0x70, 0x00, 0x00, 0x00,
|
||||||
|
0x05, 0x67, 0x6f, 0x70, 0x6c, 0x73, 0x00, 0x00, 0x00, 0x05, 0x73, 0x65,
|
||||||
|
0x72, 0x76, 0x65, 0x00, 0x00, 0x00, 0x17, 0x68, 0x61, 0x73, 0x6b, 0x65,
|
||||||
|
0x6c, 0x6c, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d,
|
||||||
|
0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x03, 0x6c, 0x73,
|
||||||
|
0x70, 0x00, 0x00, 0x00, 0x15, 0x65, 0x6d, 0x6d, 0x65, 0x74, 0x2d, 0x6c,
|
||||||
|
0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76,
|
||||||
|
0x65, 0x72, 0x00, 0x00, 0x00, 0x1a, 0x74, 0x79, 0x70, 0x65, 0x73, 0x63,
|
||||||
|
0x72, 0x69, 0x70, 0x74, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67,
|
||||||
|
0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x13,
|
||||||
|
0x6c, 0x75, 0x61, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65,
|
||||||
|
0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x12, 0x70,
|
||||||
|
0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x73,
|
||||||
|
0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x0d, 0x72, 0x75, 0x73,
|
||||||
|
0x74, 0x2d, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x72, 0x00, 0x00,
|
||||||
|
0x00, 0x0c, 0x69, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x70, 0x68, 0x65, 0x6e,
|
||||||
|
0x73, 0x65, 0x00, 0x00, 0x00, 0x08, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x6d,
|
||||||
|
0x61, 0x6e, 0x00, 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
|
||||||
|
0x00, 0x00, 0x00, 0x15, 0x6e, 0x67, 0x69, 0x6e, 0x78, 0x2d, 0x6c, 0x61,
|
||||||
|
0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65,
|
||||||
|
0x72, 0x00, 0x00, 0x00, 0x05, 0x74, 0x61, 0x70, 0x6c, 0x6f, 0x00, 0x00,
|
||||||
|
0x00, 0x14, 0x79, 0x61, 0x6d, 0x6c, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75,
|
||||||
|
0x61, 0x67, 0x65, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00,
|
||||||
|
0x00, 0x04, 0x73, 0x71, 0x6c, 0x73, 0x00, 0x00, 0x00, 0x14, 0x6d, 0x61,
|
||||||
|
0x6b, 0x65, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d,
|
||||||
|
0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x13, 0x73, 0x71,
|
||||||
|
0x6c, 0x2d, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x2d, 0x73,
|
||||||
|
0x65, 0x72, 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x02, 0x75, 0x70, 0x00,
|
||||||
|
0x00, 0x00, 0x08, 0x2d, 0x2d, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x00,
|
||||||
|
0x00, 0x00, 0x04, 0xee, 0x98, 0x9e, 0x20, 0x00, 0x00, 0x00, 0x01, 0x63,
|
||||||
|
0x00, 0x00, 0x00, 0x04, 0xee, 0x98, 0x9d, 0x20, 0x00, 0x00, 0x00, 0x03,
|
||||||
|
0x63, 0x70, 0x70, 0x00, 0x00, 0x00, 0x02, 0x63, 0x63, 0x00, 0x00, 0x00,
|
||||||
|
0x03, 0x63, 0x78, 0x78, 0x00, 0x00, 0x00, 0x04, 0xef, 0x83, 0xbd, 0x20,
|
||||||
|
0x00, 0x00, 0x00, 0x01, 0x68, 0x00, 0x00, 0x00, 0x03, 0x68, 0x70, 0x70,
|
||||||
|
0x00, 0x00, 0x00, 0x04, 0xee, 0x9a, 0xb8, 0x20, 0x00, 0x00, 0x00, 0x03,
|
||||||
|
0x63, 0x73, 0x73, 0x00, 0x00, 0x00, 0x04, 0xee, 0xb9, 0x81, 0x20, 0x00,
|
||||||
|
0x00, 0x00, 0x04, 0x66, 0x69, 0x73, 0x68, 0x00, 0x00, 0x00, 0x04, 0xee,
|
||||||
|
0x98, 0xa7, 0x20, 0x00, 0x00, 0x00, 0x02, 0x67, 0x6f, 0x00, 0x00, 0x00,
|
||||||
|
0x03, 0x6d, 0x6f, 0x64, 0x00, 0x00, 0x00, 0x04, 0xee, 0x9d, 0xb7, 0x20,
|
||||||
|
0x00, 0x00, 0x00, 0x02, 0x68, 0x73, 0x00, 0x00, 0x00, 0x03, 0x6c, 0x68,
|
||||||
|
0x73, 0x00, 0x00, 0x00, 0x04, 0xef, 0x84, 0xa1, 0x20, 0x00, 0x00, 0x00,
|
||||||
|
0x04, 0x68, 0x74, 0x6d, 0x6c, 0x00, 0x00, 0x00, 0x03, 0x68, 0x74, 0x6d,
|
||||||
|
0x00, 0x00, 0x00, 0x04, 0xef, 0x8b, 0xaf, 0x20, 0x00, 0x00, 0x00, 0x02,
|
||||||
|
0x6a, 0x73, 0x00, 0x00, 0x00, 0x04, 0xee, 0x9a, 0x9d, 0x20, 0x00, 0x00,
|
||||||
|
0x00, 0x02, 0x74, 0x73, 0x00, 0x00, 0x00, 0x02, 0x7b, 0x7d, 0x00, 0x00,
|
||||||
|
0x00, 0x04, 0x6a, 0x73, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, 0x6a, 0x73,
|
||||||
|
0x6f, 0x6e, 0x63, 0x00, 0x00, 0x00, 0x03, 0x65, 0x72, 0x62, 0x00, 0x00,
|
||||||
|
0x00, 0x05, 0xf3, 0xb0, 0xa2, 0xb1, 0x20, 0x00, 0x00, 0x00, 0x03, 0x6c,
|
||||||
|
0x75, 0x61, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb0, 0x8c, 0xa0, 0x20, 0x00,
|
||||||
|
0x00, 0x00, 0x02, 0x70, 0x79, 0x00, 0x00, 0x00, 0x07, 0x70, 0x79, 0x72,
|
||||||
|
0x69, 0x67, 0x68, 0x74, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb1, 0x98, 0x97,
|
||||||
|
0x20, 0x00, 0x00, 0x00, 0x02, 0x72, 0x73, 0x00, 0x00, 0x00, 0x05, 0xf3,
|
||||||
|
0xb0, 0x8c, 0x9f, 0x20, 0x00, 0x00, 0x00, 0x03, 0x70, 0x68, 0x70, 0x00,
|
||||||
|
0x00, 0x00, 0x04, 0xee, 0xba, 0xab, 0x20, 0x00, 0x00, 0x00, 0x02, 0x6d,
|
||||||
|
0x64, 0x00, 0x00, 0x00, 0x08, 0x6d, 0x61, 0x72, 0x6b, 0x64, 0x6f, 0x77,
|
||||||
|
0x6e, 0x00, 0x00, 0x00, 0x04, 0xee, 0x98, 0x95, 0x20, 0x00, 0x00, 0x00,
|
||||||
|
0x04, 0x63, 0x6f, 0x6e, 0x66, 0x00, 0x00, 0x00, 0x04, 0xee, 0x9a, 0xb2,
|
||||||
|
0x20, 0x00, 0x00, 0x00, 0x04, 0x74, 0x6f, 0x6d, 0x6c, 0x00, 0x00, 0x00,
|
||||||
|
0x03, 0x79, 0x6d, 0x6c, 0x00, 0x00, 0x00, 0x04, 0x79, 0x61, 0x6d, 0x6c,
|
||||||
|
0x00, 0x00, 0x00, 0x04, 0xee, 0x99, 0x8d, 0x20, 0x00, 0x00, 0x00, 0x03,
|
||||||
|
0x73, 0x71, 0x6c, 0x00, 0x00, 0x00, 0x04, 0xee, 0x99, 0xb3, 0x20, 0x00,
|
||||||
|
0x00, 0x00, 0x08, 0x4d, 0x61, 0x6b, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x00,
|
||||||
|
0x00, 0x00, 0x08, 0x6d, 0x61, 0x6b, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x00,
|
||||||
|
0x00, 0x00, 0x04, 0xee, 0x99, 0x9f, 0x20, 0x00, 0x00, 0x00, 0x02, 0x67,
|
||||||
|
0x64, 0x00, 0x00, 0x00, 0x04, 0xef, 0x80, 0xad, 0x20, 0x00, 0x00, 0x00,
|
||||||
|
0x03, 0x6d, 0x61, 0x6e, 0x00, 0x00, 0x00, 0x04, 0xee, 0x9c, 0xa8, 0x20,
|
||||||
|
0x00, 0x00, 0x00, 0x04, 0x64, 0x69, 0x66, 0x66, 0x00, 0x00, 0x00, 0x05,
|
||||||
|
0x70, 0x61, 0x74, 0x63, 0x68, 0x00, 0x00, 0x00, 0x04, 0xee, 0x99, 0x9d,
|
||||||
|
0x20, 0x00, 0x00, 0x00, 0x0d, 0x67, 0x69, 0x74, 0x61, 0x74, 0x74, 0x72,
|
||||||
|
0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x00, 0x00, 0x00, 0x09, 0x67, 0x69,
|
||||||
|
0x74, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x00, 0x00, 0x00, 0x02, 0x2e,
|
||||||
|
0x2a, 0x00, 0x00, 0x00, 0x05, 0x72, 0x65, 0x67, 0x65, 0x78, 0x00, 0x00,
|
||||||
|
0x00, 0x03, 0x69, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb0, 0xb4,
|
||||||
|
0xad, 0x20, 0x00, 0x00, 0x00, 0x02, 0x72, 0x62, 0x00, 0x00, 0x00, 0x07,
|
||||||
|
0x47, 0x65, 0x6d, 0x66, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x04, 0xee,
|
||||||
|
0xaf, 0x8a, 0x20, 0x00, 0x00, 0x00, 0x02, 0x73, 0x68, 0x00, 0x00, 0x00,
|
||||||
|
0x0c, 0x62, 0x61, 0x73, 0x68, 0x5f, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c,
|
||||||
|
0x65, 0x00, 0x00, 0x00, 0x06, 0x62, 0x61, 0x73, 0x68, 0x72, 0x63, 0x00,
|
||||||
|
0x00, 0x50, 0x00, 0x0b, 0x40, 0x6c, 0x73, 0x70, 0x5f, 0x63, 0x6f, 0x6e,
|
||||||
|
0x66, 0x69, 0x67, 0x00, 0x00, 0x01, 0x63, 0x00, 0x00, 0x05, 0x63, 0x6f,
|
||||||
|
0x6c, 0x6f, 0x72, 0x00, 0x00, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c,
|
||||||
|
0x00, 0x00, 0x0a, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e,
|
||||||
|
0x73, 0x00, 0x00, 0x03, 0x6c, 0x73, 0x70, 0x00, 0x00, 0x03, 0x63, 0x70,
|
||||||
|
0x70, 0x00, 0x00, 0x01, 0x68, 0x00, 0x00, 0x03, 0x63, 0x73, 0x73, 0x00,
|
||||||
|
0x00, 0x04, 0x66, 0x69, 0x73, 0x68, 0x00, 0x00, 0x02, 0x67, 0x6f, 0x00,
|
||||||
|
0x00, 0x05, 0x67, 0x6f, 0x6d, 0x6f, 0x64, 0x00, 0x00, 0x07, 0x68, 0x61,
|
||||||
|
0x73, 0x6b, 0x65, 0x6c, 0x6c, 0x00, 0x00, 0x04, 0x68, 0x74, 0x6d, 0x6c,
|
||||||
|
0x00, 0x00, 0x0a, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, 0x69, 0x70,
|
||||||
|
0x74, 0x00, 0x00, 0x0a, 0x74, 0x79, 0x70, 0x65, 0x73, 0x63, 0x72, 0x69,
|
||||||
|
0x70, 0x74, 0x00, 0x00, 0x04, 0x6a, 0x73, 0x6f, 0x6e, 0x00, 0x00, 0x05,
|
||||||
|
0x6a, 0x73, 0x6f, 0x6e, 0x63, 0x00, 0x00, 0x03, 0x65, 0x72, 0x62, 0x00,
|
||||||
|
0x00, 0x03, 0x6c, 0x75, 0x61, 0x00, 0x00, 0x06, 0x70, 0x79, 0x74, 0x68,
|
||||||
|
0x6f, 0x6e, 0x00, 0x00, 0x04, 0x72, 0x75, 0x73, 0x74, 0x00, 0x00, 0x03,
|
||||||
|
0x70, 0x68, 0x70, 0x00, 0x00, 0x08, 0x6d, 0x61, 0x72, 0x6b, 0x64, 0x6f,
|
||||||
|
0x77, 0x6e, 0x00, 0x00, 0x05, 0x6e, 0x67, 0x69, 0x6e, 0x78, 0x00, 0x00,
|
||||||
|
0x04, 0x74, 0x6f, 0x6d, 0x6c, 0x00, 0x00, 0x04, 0x79, 0x61, 0x6d, 0x6c,
|
||||||
|
0x00, 0x00, 0x03, 0x73, 0x71, 0x6c, 0x00, 0x00, 0x04, 0x6d, 0x61, 0x6b,
|
||||||
|
0x65, 0x00, 0x00, 0x08, 0x67, 0x64, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
|
||||||
|
0x00, 0x00, 0x03, 0x6d, 0x61, 0x6e, 0x00, 0x00, 0x04, 0x64, 0x69, 0x66,
|
||||||
|
0x66, 0x00, 0x00, 0x0d, 0x67, 0x69, 0x74, 0x61, 0x74, 0x74, 0x72, 0x69,
|
||||||
|
0x62, 0x75, 0x74, 0x65, 0x73, 0x00, 0x00, 0x09, 0x67, 0x69, 0x74, 0x69,
|
||||||
|
0x67, 0x6e, 0x6f, 0x72, 0x65, 0x00, 0x00, 0x05, 0x72, 0x65, 0x67, 0x65,
|
||||||
|
0x78, 0x00, 0x00, 0x03, 0x69, 0x6e, 0x69, 0x00, 0x00, 0x04, 0x72, 0x75,
|
||||||
|
0x62, 0x79, 0x00, 0x00, 0x09, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d,
|
||||||
|
0x65, 0x73, 0x00, 0x00, 0x04, 0x62, 0x61, 0x73, 0x68, 0x00, 0x00, 0x0a,
|
||||||
|
0x40, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x73, 0x00, 0x00,
|
||||||
|
0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, 0x00, 0x02, 0x66,
|
||||||
|
0x67, 0x00, 0x00, 0x07, 0x73, 0x68, 0x65, 0x62, 0x61, 0x6e, 0x67, 0x00,
|
||||||
|
0x00, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x00, 0x00, 0x07, 0x63, 0x6f,
|
||||||
|
0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x06, 0x69, 0x74, 0x61, 0x6c,
|
||||||
|
0x69, 0x63, 0x00, 0x00, 0x06, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x00,
|
||||||
|
0x00, 0x06, 0x65, 0x73, 0x63, 0x61, 0x70, 0x65, 0x00, 0x00, 0x0d, 0x69,
|
||||||
|
0x6e, 0x74, 0x65, 0x72, 0x70, 0x6f, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e,
|
||||||
|
0x00, 0x00, 0x06, 0x72, 0x65, 0x67, 0x65, 0x78, 0x70, 0x00, 0x00, 0x06,
|
||||||
|
0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x00, 0x00, 0x04, 0x74, 0x72, 0x75,
|
||||||
|
0x65, 0x00, 0x00, 0x05, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x00, 0x00, 0x04,
|
||||||
|
0x63, 0x68, 0x61, 0x72, 0x00, 0x00, 0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f,
|
||||||
|
0x72, 0x64, 0x00, 0x00, 0x0f, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64,
|
||||||
|
0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x00, 0x00, 0x08, 0x6f,
|
||||||
|
0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x00, 0x00, 0x08, 0x66, 0x75,
|
||||||
|
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70,
|
||||||
|
0x65, 0x00, 0x00, 0x08, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74,
|
||||||
|
0x00, 0x00, 0x10, 0x76, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x69,
|
||||||
|
0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x0e, 0x76, 0x61,
|
||||||
|
0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c,
|
||||||
|
0x00, 0x00, 0x0a, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f,
|
||||||
|
0x6e, 0x00, 0x00, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76,
|
||||||
|
0x65, 0x00, 0x00, 0x05, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x00, 0x00, 0x06,
|
||||||
|
0x62, 0x72, 0x61, 0x63, 0x65, 0x31, 0x00, 0x00, 0x06, 0x62, 0x72, 0x61,
|
||||||
|
0x63, 0x65, 0x32, 0x00, 0x00, 0x06, 0x62, 0x72, 0x61, 0x63, 0x65, 0x33,
|
||||||
|
0x00, 0x00, 0x06, 0x62, 0x72, 0x61, 0x63, 0x65, 0x34, 0x00, 0x00, 0x06,
|
||||||
|
0x62, 0x72, 0x61, 0x63, 0x65, 0x35, 0x00, 0x00, 0x06, 0x40, 0x74, 0x68,
|
||||||
|
0x65, 0x6d, 0x65, 0x00, 0x00, 0x09, 0x61, 0x75, 0x74, 0x6f, 0x5f, 0x75,
|
||||||
|
0x6e, 0x69, 0x78, 0x00, 0x00, 0x0d, 0x40, 0x6c, 0x69, 0x6e, 0x65, 0x5f,
|
||||||
|
0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x73, 0x00, 0x00, 0x0d, 0x40, 0x6b,
|
||||||
|
0x65, 0x79, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x00,
|
||||||
|
0x00, 0x0a, 0x40, 0x6b, 0x65, 0x79, 0x5f, 0x62, 0x69, 0x6e, 0x64, 0x73,
|
||||||
|
0x00, 0x00, 0x0d, 0x40, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68,
|
||||||
|
0x74, 0x65, 0x72, 0x73, 0x00, 0x00, 0x0a, 0x40, 0x62, 0x5f, 0x73, 0x74,
|
||||||
|
0x61, 0x72, 0x74, 0x75, 0x70, 0x00, 0x00, 0x0b, 0x40, 0x62, 0x5f, 0x73,
|
||||||
|
0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x00, 0x00, 0x06, 0x6c, 0x61,
|
||||||
|
0x6d, 0x62, 0x64, 0x61, 0x00, 0x00, 0x06, 0x40, 0x62, 0x5f, 0x62, 0x61,
|
||||||
|
0x72, 0x00, 0x00, 0x00, 0x03, 0x47, 0x00, 0x09, 0x00, 0x14, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x02, 0x17, 0x34, 0x04, 0x00, 0x00, 0x0f, 0x03,
|
||||||
|
0x00, 0x82, 0xaa, 0xff, 0x51, 0x04, 0x00, 0x01, 0x09, 0x01, 0x10, 0x0a,
|
||||||
|
0x00, 0x23, 0x09, 0x10, 0x0a, 0x01, 0x01, 0x0b, 0x09, 0x2f, 0x0a, 0x02,
|
||||||
|
0x01, 0x26, 0x0a, 0x00, 0x03, 0x25, 0x00, 0x0c, 0x0f, 0x03, 0x00, 0x82,
|
||||||
|
0xaa, 0xff, 0x51, 0x04, 0x01, 0x25, 0x00, 0x74, 0x10, 0x0a, 0x03, 0x01,
|
||||||
|
0x0b, 0x09, 0x2f, 0x0a, 0x02, 0x01, 0x26, 0x0a, 0x00, 0x03, 0x25, 0x00,
|
||||||
|
0x0c, 0x0f, 0x03, 0x00, 0xff, 0x8f, 0x40, 0x51, 0x04, 0x02, 0x25, 0x00,
|
||||||
|
0x57, 0x10, 0x0a, 0x04, 0x01, 0x0b, 0x09, 0x2f, 0x0a, 0x02, 0x01, 0x26,
|
||||||
|
0x0a, 0x00, 0x03, 0x25, 0x00, 0x0c, 0x0f, 0x03, 0x00, 0x9a, 0xde, 0x7a,
|
||||||
|
0x51, 0x04, 0x03, 0x25, 0x00, 0x3a, 0x10, 0x0a, 0x05, 0x01, 0x0b, 0x09,
|
||||||
|
0x2f, 0x0a, 0x02, 0x01, 0x26, 0x0a, 0x00, 0x03, 0x25, 0x00, 0x0c, 0x0f,
|
||||||
|
0x03, 0x00, 0xff, 0xd7, 0x00, 0x51, 0x04, 0x04, 0x25, 0x00, 0x1d, 0x10,
|
||||||
|
0x0a, 0x06, 0x01, 0x0b, 0x09, 0x2f, 0x0a, 0x02, 0x01, 0x26, 0x0a, 0x00,
|
||||||
|
0x03, 0x25, 0x00, 0x0c, 0x0f, 0x03, 0x00, 0xf2, 0x9c, 0xc3, 0x51, 0x04,
|
||||||
|
0x05, 0x25, 0x00, 0x00, 0x1d, 0x09, 0x07, 0x2f, 0x09, 0x08, 0x00, 0x01,
|
||||||
|
0x0a, 0x01, 0x10, 0x0b, 0x09, 0x23, 0x0a, 0x23, 0x09, 0x01, 0x05, 0x09,
|
||||||
|
0x1d, 0x09, 0x0a, 0x01, 0x0a, 0x01, 0x10, 0x0b, 0x0b, 0x23, 0x0a, 0x2f,
|
||||||
|
0x09, 0x0c, 0x01, 0x01, 0x06, 0x09, 0x51, 0x09, 0x06, 0x01, 0x0a, 0x04,
|
||||||
|
0x52, 0x09, 0x51, 0x0a, 0x06, 0x52, 0x09, 0x01, 0x0a, 0x01, 0x10, 0x0b,
|
||||||
|
0x00, 0x23, 0x0a, 0x2f, 0x0a, 0x0d, 0x00, 0x2f, 0x0a, 0x0e, 0x00, 0x52,
|
||||||
|
0x09, 0x51, 0x0a, 0x07, 0x52, 0x09, 0x01, 0x0a, 0x05, 0x10, 0x0b, 0x0f,
|
||||||
|
0x23, 0x0a, 0x52, 0x09, 0x51, 0x0a, 0x08, 0x52, 0x09, 0x01, 0x0a, 0x06,
|
||||||
|
0x52, 0x09, 0x51, 0x0a, 0x09, 0x52, 0x09, 0x01, 0x07, 0x09, 0x47, 0x08,
|
||||||
|
0x00, 0x01, 0x09, 0x08, 0x10, 0x0a, 0x10, 0x0f, 0x0b, 0x00, 0x0b, 0x0e,
|
||||||
|
0x14, 0x10, 0x0c, 0x11, 0x01, 0x0d, 0x03, 0x10, 0x0e, 0x12, 0x08, 0x0f,
|
||||||
|
0x10, 0x10, 0x13, 0x06, 0x11, 0x10, 0x12, 0x14, 0x03, 0x13, 0x0a, 0x53,
|
||||||
|
0x0a, 0x05, 0x2f, 0x09, 0x15, 0x01, 0x01, 0x09, 0x08, 0x10, 0x0a, 0x10,
|
||||||
|
0x01, 0x0b, 0x03, 0x10, 0x0c, 0x11, 0x0f, 0x0d, 0x00, 0x33, 0x36, 0x3c,
|
||||||
|
0x10, 0x0e, 0x13, 0x03, 0x0f, 0x0a, 0x10, 0x10, 0x14, 0x07, 0x11, 0x53,
|
||||||
|
0x0a, 0x04, 0x2f, 0x09, 0x15, 0x01, 0x01, 0x09, 0x08, 0x10, 0x0a, 0x10,
|
||||||
|
0x0f, 0x0b, 0x00, 0x33, 0x36, 0x3c, 0x10, 0x0c, 0x11, 0x0f, 0x0d, 0x00,
|
||||||
|
0x24, 0x27, 0x2d, 0x10, 0x0e, 0x13, 0x03, 0x0f, 0x0b, 0x10, 0x10, 0x14,
|
||||||
|
0x07, 0x11, 0x53, 0x0a, 0x04, 0x2f, 0x09, 0x15, 0x01, 0x01, 0x09, 0x08,
|
||||||
|
0x10, 0x0a, 0x10, 0x01, 0x0b, 0x05, 0x10, 0x0c, 0x16, 0x23, 0x0b, 0x10,
|
||||||
|
0x0c, 0x11, 0x0f, 0x0d, 0x00, 0x24, 0x27, 0x2d, 0x10, 0x0e, 0x13, 0x03,
|
||||||
|
0x0f, 0x0d, 0x10, 0x10, 0x14, 0x08, 0x11, 0x53, 0x0a, 0x04, 0x2f, 0x09,
|
||||||
|
0x15, 0x01, 0x01, 0x09, 0x08, 0x10, 0x0a, 0x10, 0x0f, 0x0b, 0x00, 0xce,
|
||||||
|
0xd4, 0xdf, 0x10, 0x0c, 0x11, 0x0f, 0x0d, 0x00, 0x24, 0x27, 0x2d, 0x10,
|
||||||
|
0x0e, 0x13, 0x03, 0x0f, 0x0f, 0x10, 0x10, 0x14, 0x01, 0x11, 0x06, 0x2f,
|
||||||
|
0x11, 0x14, 0x00, 0x53, 0x0a, 0x04, 0x2f, 0x09, 0x15, 0x01, 0x01, 0x09,
|
||||||
|
0x08, 0x10, 0x0a, 0x10, 0x0f, 0x0b, 0x00, 0x24, 0x27, 0x2d, 0x10, 0x0c,
|
||||||
|
0x11, 0x06, 0x0d, 0x10, 0x0e, 0x13, 0x03, 0x0f, 0x0f, 0x01, 0x10, 0x06,
|
||||||
|
0x2f, 0x10, 0x14, 0x00, 0x3c, 0x0f, 0x10, 0x10, 0x14, 0x07, 0x11, 0x53,
|
||||||
|
0x0a, 0x04, 0x2f, 0x09, 0x15, 0x01, 0x10, 0x09, 0x17, 0x01, 0x0a, 0x07,
|
||||||
|
0x10, 0x0b, 0x18, 0x01, 0x0c, 0x08, 0x53, 0x09, 0x02, 0x39, 0x09, 0x38,
|
||||||
|
0x09, 0x00, 0x0a, 0x00, 0x00, 0x02, 0x20, 0x20, 0x00, 0x00, 0x00, 0x04,
|
||||||
|
0xee, 0x99, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb1, 0x93, 0xa7,
|
||||||
|
0x20, 0x00, 0x00, 0x00, 0x05, 0xf3, 0xb1, 0xa9, 0xa7, 0x20, 0x00, 0x00,
|
||||||
|
0x00, 0x04, 0xef, 0x84, 0xa0, 0x20, 0x00, 0x00, 0x00, 0x04, 0xee, 0xba,
|
||||||
|
0xa2, 0x20, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x08, 0x20,
|
||||||
|
0xee, 0x82, 0xb4, 0xee, 0x82, 0xb4, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x03, 0xee, 0x82, 0xb4, 0x00, 0x00, 0x19, 0x00, 0x04, 0x6d,
|
||||||
|
0x6f, 0x64, 0x65, 0x00, 0x00, 0x06, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c,
|
||||||
|
0x00, 0x00, 0x03, 0x3d, 0x3d, 0x3d, 0x00, 0x00, 0x06, 0x69, 0x6e, 0x73,
|
||||||
|
0x65, 0x72, 0x74, 0x00, 0x00, 0x06, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74,
|
||||||
|
0x00, 0x00, 0x06, 0x72, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x00, 0x00, 0x06,
|
||||||
|
0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x00, 0x00, 0x01, 0x43, 0x00, 0x00,
|
||||||
|
0x09, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x73, 0x00, 0x00,
|
||||||
|
0x09, 0x6c, 0x61, 0x6e, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x00,
|
||||||
|
0x04, 0x46, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x08, 0x66, 0x69, 0x6c, 0x65,
|
||||||
|
0x6e, 0x61, 0x6d, 0x65, 0x00, 0x00, 0x08, 0x62, 0x61, 0x73, 0x65, 0x6e,
|
||||||
|
0x61, 0x6d, 0x65, 0x00, 0x00, 0x04, 0x74, 0x6f, 0x5f, 0x73, 0x00, 0x00,
|
||||||
|
0x06, 0x75, 0x70, 0x63, 0x61, 0x73, 0x65, 0x00, 0x00, 0x06, 0x73, 0x79,
|
||||||
|
0x6d, 0x62, 0x6f, 0x6c, 0x00, 0x00, 0x02, 0x66, 0x67, 0x00, 0x00, 0x02,
|
||||||
|
0x62, 0x67, 0x00, 0x00, 0x05, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x00, 0x00,
|
||||||
|
0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x00, 0x06, 0x6c, 0x65, 0x6e,
|
||||||
|
0x67, 0x74, 0x68, 0x00, 0x00, 0x02, 0x3c, 0x3c, 0x00, 0x00, 0x05, 0x63,
|
||||||
|
0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x04, 0x74, 0x65, 0x78, 0x74, 0x00,
|
||||||
|
0x00, 0x0a, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73,
|
||||||
|
0x00, 0x00, 0x00, 0x01, 0x1b, 0x00, 0x01, 0x00, 0x08, 0x00, 0x04, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x45, 0x10, 0x02, 0x00, 0x10, 0x03, 0x01, 0x10,
|
||||||
|
0x04, 0x02, 0x10, 0x05, 0x03, 0x10, 0x06, 0x04, 0x2d, 0x01, 0x05, 0x05,
|
||||||
|
0x10, 0x02, 0x06, 0x10, 0x03, 0x07, 0x10, 0x04, 0x08, 0x10, 0x05, 0x09,
|
||||||
|
0x2d, 0x01, 0x0a, 0x04, 0x63, 0x01, 0x58, 0x02, 0x00, 0x5f, 0x01, 0x0b,
|
||||||
|
0x63, 0x01, 0x58, 0x02, 0x01, 0x5f, 0x01, 0x0c, 0x63, 0x01, 0x58, 0x02,
|
||||||
|
0x02, 0x5f, 0x01, 0x0d, 0x63, 0x01, 0x58, 0x02, 0x03, 0x5f, 0x01, 0x0e,
|
||||||
|
0x38, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x05, 0x74, 0x68, 0x65, 0x6d,
|
||||||
|
0x65, 0x00, 0x00, 0x0a, 0x6c, 0x73, 0x70, 0x5f, 0x63, 0x6f, 0x6e, 0x66,
|
||||||
|
0x69, 0x67, 0x00, 0x00, 0x09, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67,
|
||||||
|
0x65, 0x73, 0x00, 0x00, 0x0c, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x65, 0x6e,
|
||||||
|
0x64, 0x69, 0x6e, 0x67, 0x73, 0x00, 0x00, 0x0c, 0x68, 0x69, 0x67, 0x68,
|
||||||
|
0x6c, 0x69, 0x67, 0x68, 0x74, 0x65, 0x72, 0x73, 0x00, 0x00, 0x0d, 0x61,
|
||||||
|
0x74, 0x74, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x6f, 0x72,
|
||||||
|
0x00, 0x00, 0x09, 0x62, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x75, 0x70,
|
||||||
|
0x00, 0x00, 0x0a, 0x62, 0x5f, 0x73, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77,
|
||||||
|
0x6e, 0x00, 0x00, 0x12, 0x62, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x5f,
|
||||||
|
0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73, 0x00, 0x00,
|
||||||
|
0x05, 0x62, 0x5f, 0x62, 0x61, 0x72, 0x00, 0x00, 0x0b, 0x61, 0x74, 0x74,
|
||||||
|
0x72, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x65, 0x72, 0x00, 0x00, 0x07, 0x73,
|
||||||
|
0x74, 0x61, 0x72, 0x74, 0x75, 0x70, 0x00, 0x00, 0x08, 0x73, 0x68, 0x75,
|
||||||
|
0x74, 0x64, 0x6f, 0x77, 0x6e, 0x00, 0x00, 0x10, 0x65, 0x78, 0x74, 0x72,
|
||||||
|
0x61, 0x5f, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73,
|
||||||
|
0x00, 0x00, 0x04, 0x62, 0x69, 0x6e, 0x64, 0x00, 0x00, 0x00, 0x00, 0x2d,
|
||||||
|
0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,
|
||||||
|
0x34, 0x00, 0x00, 0x01, 0x01, 0x02, 0x01, 0x1a, 0x02, 0x00, 0x38, 0x02,
|
||||||
|
0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x40, 0x62, 0x5f, 0x73, 0x74, 0x61,
|
||||||
|
0x72, 0x74, 0x75, 0x70, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x02, 0x00,
|
||||||
|
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x34, 0x00, 0x00,
|
||||||
|
0x01, 0x01, 0x02, 0x01, 0x1a, 0x02, 0x00, 0x38, 0x02, 0x00, 0x00, 0x00,
|
||||||
|
0x01, 0x00, 0x0b, 0x40, 0x62, 0x5f, 0x73, 0x68, 0x75, 0x74, 0x64, 0x6f,
|
||||||
|
0x77, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x02, 0x00, 0x03, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x34, 0x00, 0x00, 0x01, 0x01,
|
||||||
|
0x02, 0x01, 0x1a, 0x02, 0x00, 0x38, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||||
|
0x13, 0x40, 0x62, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x5f, 0x68, 0x69,
|
||||||
|
0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73, 0x00, 0x00, 0x00, 0x01,
|
||||||
|
0x43, 0x00, 0x07, 0x00, 0x0a, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xc1, 0x34, 0x04, 0x40, 0x01, 0x25, 0x00, 0x06, 0x25, 0x00, 0x05, 0x25,
|
||||||
|
0x00, 0x04, 0x11, 0x02, 0x11, 0x03, 0x01, 0x07, 0x01, 0x1d, 0x08, 0x00,
|
||||||
|
0x2f, 0x07, 0x01, 0x01, 0x26, 0x07, 0x00, 0x07, 0x01, 0x07, 0x01, 0x48,
|
||||||
|
0x01, 0x07, 0x01, 0x01, 0x07, 0x02, 0x28, 0x07, 0x00, 0x03, 0x25, 0x00,
|
||||||
|
0x33, 0x12, 0x05, 0x1d, 0x07, 0x02, 0x2f, 0x07, 0x03, 0x00, 0x01, 0x06,
|
||||||
|
0x07, 0x01, 0x07, 0x06, 0x10, 0x08, 0x04, 0x57, 0x09, 0x00, 0x30, 0x07,
|
||||||
|
0x05, 0x01, 0x2d, 0x07, 0x06, 0x00, 0x27, 0x07, 0x00, 0x0d, 0x01, 0x07,
|
||||||
|
0x06, 0x01, 0x08, 0x04, 0x30, 0x07, 0x07, 0x00, 0x25, 0x00, 0x02, 0x11,
|
||||||
|
0x07, 0x25, 0x00, 0x5c, 0x2d, 0x07, 0x06, 0x00, 0x27, 0x07, 0x00, 0x22,
|
||||||
|
0x01, 0x07, 0x02, 0x1d, 0x08, 0x00, 0x2f, 0x07, 0x01, 0x01, 0x26, 0x07,
|
||||||
|
0x00, 0x07, 0x01, 0x07, 0x02, 0x48, 0x02, 0x07, 0x01, 0x01, 0x07, 0x01,
|
||||||
|
0x57, 0x08, 0x01, 0x30, 0x07, 0x08, 0x00, 0x25, 0x00, 0x32, 0x01, 0x07,
|
||||||
|
0x03, 0x1d, 0x08, 0x09, 0x2f, 0x07, 0x01, 0x01, 0x27, 0x07, 0x00, 0x22,
|
||||||
|
0x01, 0x07, 0x02, 0x1d, 0x08, 0x00, 0x2f, 0x07, 0x01, 0x01, 0x26, 0x07,
|
||||||
|
0x00, 0x07, 0x01, 0x07, 0x02, 0x48, 0x02, 0x07, 0x01, 0x01, 0x07, 0x01,
|
||||||
|
0x57, 0x08, 0x02, 0x30, 0x07, 0x08, 0x00, 0x25, 0x00, 0x02, 0x11, 0x07,
|
||||||
|
0x38, 0x07, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x05, 0x41, 0x72, 0x72, 0x61,
|
||||||
|
0x79, 0x00, 0x00, 0x05, 0x69, 0x73, 0x5f, 0x61, 0x3f, 0x00, 0x00, 0x06,
|
||||||
|
0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00, 0x00, 0x03, 0x6e, 0x65, 0x77,
|
||||||
|
0x00, 0x00, 0x03, 0x73, 0x65, 0x74, 0x00, 0x00, 0x17, 0x64, 0x65, 0x66,
|
||||||
|
0x69, 0x6e, 0x65, 0x5f, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x74, 0x6f,
|
||||||
|
0x6e, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x00, 0x00, 0x0c, 0x62,
|
||||||
|
0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x67, 0x69, 0x76, 0x65, 0x6e, 0x3f, 0x00,
|
||||||
|
0x00, 0x0d, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x65,
|
||||||
|
0x78, 0x65, 0x63, 0x00, 0x00, 0x04, 0x65, 0x61, 0x63, 0x68, 0x00, 0x00,
|
||||||
|
0x06, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x3e,
|
||||||
|
0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
|
||||||
|
0x34, 0x04, 0x20, 0x01, 0x25, 0x00, 0x03, 0x25, 0x00, 0x02, 0x11, 0x02,
|
||||||
|
0x21, 0x04, 0x05, 0x00, 0x21, 0x05, 0x01, 0x00, 0x01, 0x06, 0x01, 0x01,
|
||||||
|
0x07, 0x02, 0x01, 0x08, 0x03, 0x30, 0x04, 0x00, 0x03, 0x38, 0x04, 0x00,
|
||||||
|
0x00, 0x00, 0x01, 0x00, 0x04, 0x62, 0x69, 0x6e, 0x64, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x2c, 0x00, 0x03, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x11, 0x34, 0x04, 0x00, 0x00, 0x21, 0x03, 0x02, 0x00, 0x57, 0x04,
|
||||||
|
0x00, 0x30, 0x03, 0x00, 0x00, 0x38, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||||
|
0x04, 0x65, 0x61, 0x63, 0x68, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x03,
|
||||||
|
0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x34, 0x04,
|
||||||
|
0x00, 0x00, 0x19, 0x03, 0x00, 0x21, 0x04, 0x01, 0x00, 0x01, 0x05, 0x03,
|
||||||
|
0x01, 0x06, 0x04, 0x2f, 0x05, 0x01, 0x01, 0x26, 0x05, 0x00, 0x07, 0x53,
|
||||||
|
0x05, 0x00, 0x2f, 0x03, 0x02, 0x02, 0x19, 0x03, 0x00, 0x21, 0x04, 0x01,
|
||||||
|
0x00, 0x23, 0x03, 0x01, 0x04, 0x01, 0x01, 0x05, 0x03, 0x01, 0x06, 0x04,
|
||||||
|
0x2f, 0x05, 0x01, 0x01, 0x26, 0x05, 0x00, 0x07, 0x47, 0x05, 0x00, 0x2f,
|
||||||
|
0x03, 0x02, 0x02, 0x19, 0x03, 0x00, 0x21, 0x04, 0x01, 0x00, 0x23, 0x03,
|
||||||
|
0x01, 0x04, 0x01, 0x23, 0x03, 0x21, 0x04, 0x04, 0x01, 0x2f, 0x03, 0x03,
|
||||||
|
0x01, 0x38, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0d, 0x40, 0x6b, 0x65,
|
||||||
|
0x79, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x00, 0x00,
|
||||||
|
0x02, 0x5b, 0x5d, 0x00, 0x00, 0x03, 0x5b, 0x5d, 0x3d, 0x00, 0x00, 0x02,
|
||||||
|
0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x03, 0x00, 0x05, 0x00,
|
||||||
|
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x34, 0x04, 0x00, 0x00, 0x21,
|
||||||
|
0x03, 0x02, 0x00, 0x57, 0x04, 0x00, 0x30, 0x03, 0x00, 0x00, 0x38, 0x03,
|
||||||
|
0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x65, 0x61, 0x63, 0x68, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x8a, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x59, 0x34, 0x04, 0x00, 0x00, 0x19, 0x03, 0x00, 0x21, 0x04,
|
||||||
|
0x01, 0x00, 0x01, 0x05, 0x03, 0x01, 0x06, 0x04, 0x2f, 0x05, 0x01, 0x01,
|
||||||
|
0x26, 0x05, 0x00, 0x07, 0x53, 0x05, 0x00, 0x2f, 0x03, 0x02, 0x02, 0x19,
|
||||||
|
0x03, 0x00, 0x21, 0x04, 0x01, 0x00, 0x23, 0x03, 0x01, 0x04, 0x01, 0x01,
|
||||||
|
0x05, 0x03, 0x01, 0x06, 0x04, 0x2f, 0x05, 0x01, 0x01, 0x26, 0x05, 0x00,
|
||||||
|
0x07, 0x47, 0x05, 0x00, 0x2f, 0x03, 0x02, 0x02, 0x19, 0x03, 0x00, 0x21,
|
||||||
|
0x04, 0x01, 0x00, 0x23, 0x03, 0x01, 0x04, 0x01, 0x23, 0x03, 0x21, 0x04,
|
||||||
|
0x03, 0x01, 0x2f, 0x03, 0x03, 0x01, 0x38, 0x03, 0x00, 0x00, 0x00, 0x04,
|
||||||
|
0x00, 0x0a, 0x40, 0x6b, 0x65, 0x79, 0x5f, 0x62, 0x69, 0x6e, 0x64, 0x73,
|
||||||
|
0x00, 0x00, 0x02, 0x5b, 0x5d, 0x00, 0x00, 0x03, 0x5b, 0x5d, 0x3d, 0x00,
|
||||||
|
0x00, 0x02, 0x3c, 0x3c, 0x00, 0x4c, 0x56, 0x41, 0x52, 0x00, 0x00, 0x00,
|
||||||
|
0xcc, 0x00, 0x00, 0x00, 0x12, 0x00, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x00,
|
||||||
|
0x0a, 0x6d, 0x6f, 0x64, 0x65, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00,
|
||||||
|
0x0b, 0x6d, 0x6f, 0x64, 0x65, 0x5f, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c,
|
||||||
|
0x00, 0x09, 0x6c, 0x61, 0x6e, 0x67, 0x5f, 0x69, 0x6e, 0x66, 0x6f, 0x00,
|
||||||
|
0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x08, 0x73,
|
||||||
|
0x74, 0x61, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x00, 0x0a, 0x68, 0x69, 0x67,
|
||||||
|
0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x73, 0x00, 0x05, 0x62, 0x6c, 0x6f,
|
||||||
|
0x63, 0x6b, 0x00, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x73, 0x00, 0x04, 0x6b,
|
||||||
|
0x65, 0x79, 0x73, 0x00, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x00,
|
||||||
|
0x03, 0x61, 0x70, 0x70, 0x00, 0x03, 0x64, 0x73, 0x6c, 0x00, 0x01, 0x6b,
|
||||||
|
0x00, 0x03, 0x61, 0x63, 0x74, 0x00, 0x03, 0x62, 0x6c, 0x6b, 0x00, 0x04,
|
||||||
|
0x6d, 0x6f, 0x64, 0x65, 0x00, 0x03, 0x6b, 0x65, 0x79, 0x00, 0x00, 0xff,
|
||||||
|
0xff, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00,
|
||||||
|
0x06, 0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00,
|
||||||
|
0x0a, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0e, 0x00,
|
||||||
|
0x0f, 0x00, 0x10, 0xff, 0xff, 0x00, 0x11, 0xff, 0xff, 0x00, 0x10, 0xff,
|
||||||
|
0xff, 0x00, 0x11, 0xff, 0xff, 0x45, 0x4e, 0x44, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x08
|
||||||
|
};
|
||||||
|
constexpr unsigned int _tmp___crib_precompiled_mrb_len = 7273;
|
||||||
48
include/syntax/decl.h
Normal file
48
include/syntax/decl.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#ifndef SYNTAX_DECL_H
|
||||||
|
#define SYNTAX_DECL_H
|
||||||
|
|
||||||
|
#include "io/knot.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "syntax/trie.h"
|
||||||
|
|
||||||
|
struct Highlight {
|
||||||
|
uint32_t fg{0xFFFFFF};
|
||||||
|
uint32_t bg{0x000000};
|
||||||
|
uint8_t flags{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
enum struct TokenKind : uint8_t {
|
||||||
|
#define ADD(name) name,
|
||||||
|
#include "syntax/tokens.def"
|
||||||
|
#undef ADD
|
||||||
|
Count
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr size_t TOKEN_KIND_COUNT = static_cast<size_t>(TokenKind::Count);
|
||||||
|
|
||||||
|
const std::unordered_map<std::string, TokenKind> kind_map = {
|
||||||
|
#define ADD(name) {#name, TokenKind::name},
|
||||||
|
#include "syntax/tokens.def"
|
||||||
|
#undef ADD
|
||||||
|
};
|
||||||
|
|
||||||
|
extern std::array<Highlight, TOKEN_KIND_COUNT> highlights;
|
||||||
|
|
||||||
|
struct Token {
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t end;
|
||||||
|
TokenKind type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LineData {
|
||||||
|
std::shared_ptr<void> in_state{nullptr};
|
||||||
|
std::vector<Token> tokens;
|
||||||
|
std::shared_ptr<void> out_state{nullptr};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CustomState {
|
||||||
|
mrb_value state;
|
||||||
|
CustomState(mrb_value s) : state(s) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
490
include/syntax/extras.h
Normal file
490
include/syntax/extras.h
Normal file
@@ -0,0 +1,490 @@
|
|||||||
|
#ifndef SYNTAX_EXTRAS_H
|
||||||
|
#define SYNTAX_EXTRAS_H
|
||||||
|
|
||||||
|
#include "io/knot.h"
|
||||||
|
#include "syntax/decl.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
inline static const std::vector<std::pair<std::string, uint32_t>> color_map = {
|
||||||
|
{"AliceBlue", 0xF0F8FF},
|
||||||
|
{"AntiqueWhite", 0xFAEBD7},
|
||||||
|
{"Aqua", 0x00FFFF},
|
||||||
|
{"Aquamarine", 0x7FFFD4},
|
||||||
|
{"Azure", 0xF0FFFF},
|
||||||
|
{"Beige", 0xF5F5DC},
|
||||||
|
{"Bisque", 0xFFE4C4},
|
||||||
|
{"Black", 0x000000},
|
||||||
|
{"BlanchedAlmond", 0xFFEBCD},
|
||||||
|
{"Blue", 0x0000FF},
|
||||||
|
{"BlueViolet", 0x8A2BE2},
|
||||||
|
{"Brown", 0xA52A2A},
|
||||||
|
{"BurlyWood", 0xDEB887},
|
||||||
|
{"CadetBlue", 0x5F9EA0},
|
||||||
|
{"Chartreuse", 0x7FFF00},
|
||||||
|
{"Chocolate", 0xD2691E},
|
||||||
|
{"Coral", 0xFF7F50},
|
||||||
|
{"CornflowerBlue", 0x6495ED},
|
||||||
|
{"Cornsilk", 0xFFF8DC},
|
||||||
|
{"Crimson", 0xDC143C},
|
||||||
|
{"Cyan", 0x00FFFF},
|
||||||
|
{"DarkBlue", 0x00008B},
|
||||||
|
{"DarkCyan", 0x008B8B},
|
||||||
|
{"DarkGoldenRod", 0xB8860B},
|
||||||
|
{"DarkGray", 0xA9A9A9},
|
||||||
|
{"DarkGrey", 0xA9A9A9},
|
||||||
|
{"DarkGreen", 0x006400},
|
||||||
|
{"DarkKhaki", 0xBDB76B},
|
||||||
|
{"DarkMagenta", 0x8B008B},
|
||||||
|
{"DarkOliveGreen", 0x556B2F},
|
||||||
|
{"DarkOrange", 0xFF8C00},
|
||||||
|
{"DarkOrchid", 0x9932CC},
|
||||||
|
{"DarkRed", 0x8B0000},
|
||||||
|
{"DarkSalmon", 0xE9967A},
|
||||||
|
{"DarkSeaGreen", 0x8FBC8F},
|
||||||
|
{"DarkSlateBlue", 0x483D8B},
|
||||||
|
{"DarkSlateGray", 0x2F4F4F},
|
||||||
|
{"DarkSlateGrey", 0x2F4F4F},
|
||||||
|
{"DarkTurquoise", 0x00CED1},
|
||||||
|
{"DarkViolet", 0x9400D3},
|
||||||
|
{"DeepPink", 0xFF1493},
|
||||||
|
{"DeepSkyBlue", 0x00BFFF},
|
||||||
|
{"DimGray", 0x696969},
|
||||||
|
{"DimGrey", 0x696969},
|
||||||
|
{"DodgerBlue", 0x1E90FF},
|
||||||
|
{"FireBrick", 0xB22222},
|
||||||
|
{"FloralWhite", 0xFFFAF0},
|
||||||
|
{"ForestGreen", 0x228B22},
|
||||||
|
{"Fuchsia", 0xFF00FF},
|
||||||
|
{"Gainsboro", 0xDCDCDC},
|
||||||
|
{"GhostWhite", 0xF8F8FF},
|
||||||
|
{"Gold", 0xFFD700},
|
||||||
|
{"GoldenRod", 0xDAA520},
|
||||||
|
{"Gray", 0x808080},
|
||||||
|
{"Grey", 0x808080},
|
||||||
|
{"Green", 0x008000},
|
||||||
|
{"GreenYellow", 0xADFF2F},
|
||||||
|
{"HoneyDew", 0xF0FFF0},
|
||||||
|
{"HotPink", 0xFF69B4},
|
||||||
|
{"IndianRed", 0xCD5C5C},
|
||||||
|
{"Indigo", 0x4B0082},
|
||||||
|
{"Ivory", 0xFFFFF0},
|
||||||
|
{"Khaki", 0xF0E68C},
|
||||||
|
{"Lavender", 0xE6E6FA},
|
||||||
|
{"LavenderBlush", 0xFFF0F5},
|
||||||
|
{"LawnGreen", 0x7CFC00},
|
||||||
|
{"LemonChiffon", 0xFFFACD},
|
||||||
|
{"LightBlue", 0xADD8E6},
|
||||||
|
{"LightCoral", 0xF08080},
|
||||||
|
{"LightCyan", 0xE0FFFF},
|
||||||
|
{"LightGoldenRodYellow", 0xFAFAD2},
|
||||||
|
{"LightGray", 0xD3D3D3},
|
||||||
|
{"LightGrey", 0xD3D3D3},
|
||||||
|
{"LightGreen", 0x90EE90},
|
||||||
|
{"LightPink", 0xFFB6C1},
|
||||||
|
{"LightSalmon", 0xFFA07A},
|
||||||
|
{"LightSeaGreen", 0x20B2AA},
|
||||||
|
{"LightSkyBlue", 0x87CEFA},
|
||||||
|
{"LightSlateGray", 0x778899},
|
||||||
|
{"LightSlateGrey", 0x778899},
|
||||||
|
{"LightSteelBlue", 0xB0C4DE},
|
||||||
|
{"LightYellow", 0xFFFFE0},
|
||||||
|
{"Lime", 0x00FF00},
|
||||||
|
{"LimeGreen", 0x32CD32},
|
||||||
|
{"Linen", 0xFAF0E6},
|
||||||
|
{"Magenta", 0xFF00FF},
|
||||||
|
{"Maroon", 0x800000},
|
||||||
|
{"MediumAquaMarine", 0x66CDAA},
|
||||||
|
{"MediumBlue", 0x0000CD},
|
||||||
|
{"MediumOrchid", 0xBA55D3},
|
||||||
|
{"MediumPurple", 0x9370DB},
|
||||||
|
{"MediumSeaGreen", 0x3CB371},
|
||||||
|
{"MediumSlateBlue", 0x7B68EE},
|
||||||
|
{"MediumSpringGreen", 0x00FA9A},
|
||||||
|
{"MediumTurquoise", 0x48D1CC},
|
||||||
|
{"MediumVioletRed", 0xC71585},
|
||||||
|
{"MidnightBlue", 0x191970},
|
||||||
|
{"MintCream", 0xF5FFFA},
|
||||||
|
{"MistyRose", 0xFFE4E1},
|
||||||
|
{"Moccasin", 0xFFE4B5},
|
||||||
|
{"NavajoWhite", 0xFFDEAD},
|
||||||
|
{"Navy", 0x000080},
|
||||||
|
{"OldLace", 0xFDF5E6},
|
||||||
|
{"Olive", 0x808000},
|
||||||
|
{"OliveDrab", 0x6B8E23},
|
||||||
|
{"Orange", 0xFFA500},
|
||||||
|
{"OrangeRed", 0xFF4500},
|
||||||
|
{"Orchid", 0xDA70D6},
|
||||||
|
{"PaleGoldenRod", 0xEEE8AA},
|
||||||
|
{"PaleGreen", 0x98FB98},
|
||||||
|
{"PaleTurquoise", 0xAFEEEE},
|
||||||
|
{"PaleVioletRed", 0xDB7093},
|
||||||
|
{"PapayaWhip", 0xFFEFD5},
|
||||||
|
{"PeachPuff", 0xFFDAB9},
|
||||||
|
{"Peru", 0xCD853F},
|
||||||
|
{"Pink", 0xFFC0CB},
|
||||||
|
{"Plum", 0xDDA0DD},
|
||||||
|
{"PowderBlue", 0xB0E0E6},
|
||||||
|
{"Purple", 0x800080},
|
||||||
|
{"RebeccaPurple", 0x663399},
|
||||||
|
{"Red", 0xFF0000},
|
||||||
|
{"RosyBrown", 0xBC8F8F},
|
||||||
|
{"RoyalBlue", 0x4169E1},
|
||||||
|
{"SaddleBrown", 0x8B4513},
|
||||||
|
{"Salmon", 0xFA8072},
|
||||||
|
{"SandyBrown", 0xF4A460},
|
||||||
|
{"SeaGreen", 0x2E8B57},
|
||||||
|
{"SeaShell", 0xFFF5EE},
|
||||||
|
{"Sienna", 0xA0522D},
|
||||||
|
{"Silver", 0xC0C0C0},
|
||||||
|
{"SkyBlue", 0x87CEEB},
|
||||||
|
{"SlateBlue", 0x6A5ACD},
|
||||||
|
{"SlateGray", 0x708090},
|
||||||
|
{"SlateGrey", 0x708090},
|
||||||
|
{"Snow", 0xFFFAFA},
|
||||||
|
{"SpringGreen", 0x00FF7F},
|
||||||
|
{"SteelBlue", 0x4682B4},
|
||||||
|
{"Tan", 0xD2B48C},
|
||||||
|
{"Teal", 0x008080},
|
||||||
|
{"Thistle", 0xD8BFD8},
|
||||||
|
{"Tomato", 0xFF6347},
|
||||||
|
{"Turquoise", 0x40E0D0},
|
||||||
|
{"Violet", 0xEE82EE},
|
||||||
|
{"Wheat", 0xF5DEB3},
|
||||||
|
{"White", 0xFFFFFF},
|
||||||
|
{"WhiteSmoke", 0xF5F5F5},
|
||||||
|
{"Yellow", 0xFFFF00},
|
||||||
|
{"YellowGreen", 0x9ACD32},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add word under cursor to this
|
||||||
|
|
||||||
|
struct ExtraHighlighter {
|
||||||
|
std::vector<uint32_t> colors;
|
||||||
|
std::array<std::vector<uint32_t>, 50> lines;
|
||||||
|
Trie<uint32_t> css_colors = Trie<uint32_t>();
|
||||||
|
uint32_t start = 0;
|
||||||
|
|
||||||
|
ExtraHighlighter() { css_colors.build(color_map, false); }
|
||||||
|
|
||||||
|
void render(Knot *root, uint32_t n_start, std::string word, bool is_css) {
|
||||||
|
start = n_start;
|
||||||
|
for (auto &line : lines)
|
||||||
|
line.clear();
|
||||||
|
LineIterator *it = begin_l_iter(root, start);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t idx = 0;
|
||||||
|
uint32_t len;
|
||||||
|
char *line;
|
||||||
|
while (idx < 50 && (line = next_line(it, &len))) {
|
||||||
|
lines[idx].assign(len, UINT32_MAX - 1);
|
||||||
|
uint32_t i = 0;
|
||||||
|
while (i < len) {
|
||||||
|
if (is_css) {
|
||||||
|
std::optional<uint32_t> color;
|
||||||
|
uint32_t color_len = css_colors.match(
|
||||||
|
line, i, len, [](char c) { return isalnum(c) || c == '_'; },
|
||||||
|
&color);
|
||||||
|
if (color) {
|
||||||
|
for (uint32_t j = 0; j < color_len; j++)
|
||||||
|
lines[idx][i + j] = *color;
|
||||||
|
i += color_len;
|
||||||
|
continue;
|
||||||
|
} else if (i + 5 < len && (line[i] == 'r' || line[i] == 'R') &&
|
||||||
|
(line[i + 1] == 'g' || line[i + 1] == 'G') &&
|
||||||
|
(line[i + 2] == 'b' || line[i + 2] == 'B')) {
|
||||||
|
uint32_t start = i;
|
||||||
|
i += 3;
|
||||||
|
if (line[i] == 'a' || line[i] == 'A')
|
||||||
|
i++;
|
||||||
|
if (line[i] == '(') {
|
||||||
|
i++;
|
||||||
|
bool is_percent = false;
|
||||||
|
std::string r = "";
|
||||||
|
while (i < len && line[i] >= '0' && line[i] <= '9')
|
||||||
|
r += line[i++];
|
||||||
|
if (r.empty())
|
||||||
|
continue;
|
||||||
|
while (i < len &&
|
||||||
|
(line[i] == '.' || (line[i] >= '0' && line[i] <= '9')))
|
||||||
|
i++;
|
||||||
|
if (line[i] == '%') {
|
||||||
|
is_percent = true;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (i < len && (line[i] == ',' || line[i] == ' '))
|
||||||
|
i++;
|
||||||
|
std::string g = "";
|
||||||
|
while (i < len && line[i] >= '0' && line[i] <= '9')
|
||||||
|
g += line[i++];
|
||||||
|
if (g.empty())
|
||||||
|
continue;
|
||||||
|
while (i < len &&
|
||||||
|
(line[i] == '.' || (line[i] >= '0' && line[i] <= '9')))
|
||||||
|
i++;
|
||||||
|
while (i < len &&
|
||||||
|
(line[i] == ',' || line[i] == ' ' || line[i] == '%'))
|
||||||
|
i++;
|
||||||
|
std::string b = "";
|
||||||
|
while (i < len && line[i] >= '0' && line[i] <= '9')
|
||||||
|
b += line[i++];
|
||||||
|
if (b.empty())
|
||||||
|
continue;
|
||||||
|
while (i < len &&
|
||||||
|
(line[i] == ',' || line[i] == ' ' || line[i] == '.' ||
|
||||||
|
line[i] == '/' || line[i] == '%' ||
|
||||||
|
(line[i] >= '0' && line[i] <= '9')))
|
||||||
|
i++;
|
||||||
|
if (i < len && line[i] == ')')
|
||||||
|
i++;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
uint32_t rr, gg, bb;
|
||||||
|
if (is_percent) {
|
||||||
|
rr = std::stoul(r) * 255 / 100;
|
||||||
|
gg = std::stoul(g) * 255 / 100;
|
||||||
|
bb = std::stoul(b) * 255 / 100;
|
||||||
|
} else {
|
||||||
|
rr = std::stoul(r);
|
||||||
|
gg = std::stoul(g);
|
||||||
|
bb = std::stoul(b);
|
||||||
|
}
|
||||||
|
rr = rr > 255 ? 255 : rr;
|
||||||
|
gg = gg > 255 ? 255 : gg;
|
||||||
|
bb = bb > 255 ? 255 : bb;
|
||||||
|
uint32_t color = (rr << 16) | (gg << 8) | bb;
|
||||||
|
for (uint32_t j = start; j < i; j++)
|
||||||
|
lines[idx][j] = color;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
} else if (i + 5 < len && (line[i] == 'h' || line[i] == 'H') &&
|
||||||
|
(line[i + 1] == 's' || line[i + 1] == 'S') &&
|
||||||
|
(line[i + 2] == 'l' || line[i + 2] == 'L')) {
|
||||||
|
uint32_t start = i;
|
||||||
|
i += 3;
|
||||||
|
if (line[i] == 'a' || line[i] == 'A')
|
||||||
|
i++;
|
||||||
|
if (line[i] == '(') {
|
||||||
|
i++;
|
||||||
|
std::string h = "";
|
||||||
|
std::string h_unit = "";
|
||||||
|
enum unit : uint8_t { deg, grad, rad, turn };
|
||||||
|
unit u = deg;
|
||||||
|
bool negative = false;
|
||||||
|
if (i < len && (line[i] == '-' || line[i] == '+')) {
|
||||||
|
negative = line[i] == '-';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (i < len && line[i] >= '0' && line[i] <= '9')
|
||||||
|
h += line[i++];
|
||||||
|
if (i < len && line[i] == '.') {
|
||||||
|
h += '.';
|
||||||
|
while (i < len && line[i] >= '0' && line[i] <= '9')
|
||||||
|
h += line[i++];
|
||||||
|
}
|
||||||
|
if (h.empty())
|
||||||
|
continue;
|
||||||
|
while (i < len && ((line[i] >= 'a' && line[i] <= 'z') ||
|
||||||
|
(line[i] >= 'A' && line[i] <= 'Z')))
|
||||||
|
h_unit += line[i++];
|
||||||
|
for (size_t x = 0; x < h_unit.size(); x++)
|
||||||
|
h_unit[x] = tolower(h_unit[x]);
|
||||||
|
if (h_unit.empty())
|
||||||
|
u = deg;
|
||||||
|
else if (h_unit == "deg")
|
||||||
|
u = deg;
|
||||||
|
else if (h_unit == "grad")
|
||||||
|
u = grad;
|
||||||
|
else if (h_unit == "rad")
|
||||||
|
u = rad;
|
||||||
|
else if (h_unit == "turn")
|
||||||
|
u = turn;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
double hue = std::stod(h);
|
||||||
|
if (negative)
|
||||||
|
hue = -hue;
|
||||||
|
switch (u) {
|
||||||
|
case deg:
|
||||||
|
break;
|
||||||
|
case grad:
|
||||||
|
hue = hue * 360.0 / 400.0;
|
||||||
|
break;
|
||||||
|
case rad:
|
||||||
|
hue = hue * 180.0 / M_PI;
|
||||||
|
break;
|
||||||
|
case turn:
|
||||||
|
hue = hue * 360.0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
hue = fmod(hue, 360.0);
|
||||||
|
if (hue < 0)
|
||||||
|
hue += 360.0;
|
||||||
|
double h_final = hue / 360.0;
|
||||||
|
while (i < len && (line[i] == ',' || line[i] == ' '))
|
||||||
|
i++;
|
||||||
|
std::string s = "";
|
||||||
|
while (i < len && line[i] >= '0' && line[i] <= '9')
|
||||||
|
s += line[i++];
|
||||||
|
if (s.empty())
|
||||||
|
continue;
|
||||||
|
if (i < len && line[i] == '%')
|
||||||
|
i++;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
while (i < len && (line[i] == ',' || line[i] == ' '))
|
||||||
|
i++;
|
||||||
|
std::string l = "";
|
||||||
|
while (i < len && line[i] >= '0' && line[i] <= '9')
|
||||||
|
l += line[i++];
|
||||||
|
if (l.empty())
|
||||||
|
continue;
|
||||||
|
if (i < len && line[i] == '%')
|
||||||
|
i++;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
while (i < len &&
|
||||||
|
(line[i] == ',' || line[i] == ' ' || line[i] == '.' ||
|
||||||
|
line[i] == '/' || line[i] == '%' ||
|
||||||
|
(line[i] >= '0' && line[i] <= '9')))
|
||||||
|
i++;
|
||||||
|
if (i < len && line[i] == ')')
|
||||||
|
i++;
|
||||||
|
double s_val = std::stod(s) / 100.0;
|
||||||
|
double l_val = std::stod(l) / 100.0;
|
||||||
|
uint32_t color = hslToRgb(h_final, s_val, l_val);
|
||||||
|
for (uint32_t j = start; j < i; j++)
|
||||||
|
lines[idx][j] = color;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i + 4 < len && line[i] == '#') {
|
||||||
|
i++;
|
||||||
|
uint32_t start = i;
|
||||||
|
while (i < len && isxdigit(line[i]))
|
||||||
|
i++;
|
||||||
|
uint32_t color = 0;
|
||||||
|
if (is_css && (i - start == 3 || i - start == 4)) {
|
||||||
|
uint32_t r =
|
||||||
|
std::stoul(std::string(line + start, 1), nullptr, 16) * 0x11;
|
||||||
|
uint32_t g =
|
||||||
|
std::stoul(std::string(line + start + 1, 1), nullptr, 16) *
|
||||||
|
0x11;
|
||||||
|
uint32_t b =
|
||||||
|
std::stoul(std::string(line + start + 2, 1), nullptr, 16) *
|
||||||
|
0x11;
|
||||||
|
color = (r << 16) | (g << 8) | b;
|
||||||
|
} else if ((is_css && (i - start == 8)) || i - start == 6) {
|
||||||
|
uint32_t r = std::stoul(std::string(line + start, 2), nullptr, 16);
|
||||||
|
uint32_t g =
|
||||||
|
std::stoul(std::string(line + start + 2, 2), nullptr, 16);
|
||||||
|
uint32_t b =
|
||||||
|
std::stoul(std::string(line + start + 4, 2), nullptr, 16);
|
||||||
|
color = (r << 16) | (g << 8) | b;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (uint32_t j = start - 1; j < i; j++)
|
||||||
|
lines[idx][j] = color;
|
||||||
|
continue;
|
||||||
|
} else if (i + 5 < len && line[i] == '0' && line[i + 1] == 'x') {
|
||||||
|
i += 2;
|
||||||
|
uint32_t start = i;
|
||||||
|
while (i < len && isxdigit(line[i]))
|
||||||
|
i++;
|
||||||
|
uint32_t color = 0;
|
||||||
|
if (i - start == 6) {
|
||||||
|
uint32_t r = std::stoul(std::string(line + start, 2), nullptr, 16);
|
||||||
|
uint32_t g =
|
||||||
|
std::stoul(std::string(line + start + 2, 2), nullptr, 16);
|
||||||
|
uint32_t b =
|
||||||
|
std::stoul(std::string(line + start + 4, 2), nullptr, 16);
|
||||||
|
color = (r << 16) | (g << 8) | b;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (color)
|
||||||
|
color--;
|
||||||
|
else
|
||||||
|
color++;
|
||||||
|
for (uint32_t j = start - 2; j < i; j++)
|
||||||
|
lines[idx][j] = color;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i < len && (isalnum(line[i]) || line[i] == '_')) {
|
||||||
|
uint32_t start = i;
|
||||||
|
uint32_t x = 0;
|
||||||
|
bool found = true;
|
||||||
|
while (i < len && (isalnum(line[i]) || line[i] == '_')) {
|
||||||
|
if (x < word.size() && line[i] == word[x]) {
|
||||||
|
i++;
|
||||||
|
x++;
|
||||||
|
} else {
|
||||||
|
found = false;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found && x == word.size())
|
||||||
|
for (uint32_t j = start; j < i; j++)
|
||||||
|
lines[idx][j] = UINT32_MAX;
|
||||||
|
} else {
|
||||||
|
i += utf8_codepoint_width(line[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::pair<uint32_t, uint32_t>> get(Coord pos) {
|
||||||
|
uint32_t val;
|
||||||
|
if (pos.row < start || pos.row >= start + 50 ||
|
||||||
|
pos.col >= lines[pos.row - start].size() ||
|
||||||
|
(val = lines[pos.row - start][pos.col]) == UINT32_MAX - 1)
|
||||||
|
return std::nullopt;
|
||||||
|
return (std::pair<uint32_t, uint32_t>){fg_for_bg(val), val};
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t fg_for_bg(uint32_t color) {
|
||||||
|
uint8_t r = (color >> 16) & 0xFF;
|
||||||
|
uint8_t g = (color >> 8) & 0xFF;
|
||||||
|
uint8_t b = color & 0xFF;
|
||||||
|
double luminance = 0.299 * r + 0.587 * g + 0.114 * b;
|
||||||
|
return (luminance > 128) ? 0x010101 : 0xFFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t hslToRgb(double h, double s, double l) {
|
||||||
|
double r, g, b;
|
||||||
|
if (s == 0.0) {
|
||||||
|
r = g = b = l;
|
||||||
|
} else {
|
||||||
|
auto hue2rgb = [](double p, double q, double t) -> double {
|
||||||
|
if (t < 0)
|
||||||
|
t += 1;
|
||||||
|
if (t > 1)
|
||||||
|
t -= 1;
|
||||||
|
if (t < 1.0 / 6)
|
||||||
|
return p + (q - p) * 6 * t;
|
||||||
|
if (t < 1.0 / 2)
|
||||||
|
return q;
|
||||||
|
if (t < 2.0 / 3)
|
||||||
|
return p + (q - p) * (2.0 / 3 - t) * 6;
|
||||||
|
return p;
|
||||||
|
};
|
||||||
|
double q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
||||||
|
double p = 2 * l - q;
|
||||||
|
r = hue2rgb(p, q, h + 1.0 / 3);
|
||||||
|
g = hue2rgb(p, q, h);
|
||||||
|
b = hue2rgb(p, q, h - 1.0 / 3);
|
||||||
|
}
|
||||||
|
uint32_t R = static_cast<uint32_t>(std::clamp(r, 0.0, 1.0) * 255);
|
||||||
|
uint32_t G = static_cast<uint32_t>(std::clamp(g, 0.0, 1.0) * 255);
|
||||||
|
uint32_t B = static_cast<uint32_t>(std::clamp(b, 0.0, 1.0) * 255);
|
||||||
|
return (R << 16) | (G << 8) | B;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
47
include/syntax/langs.h
Normal file
47
include/syntax/langs.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#ifndef SYNTAX_LANGS_H
|
||||||
|
#define SYNTAX_LANGS_H
|
||||||
|
|
||||||
|
#include "syntax/decl.h"
|
||||||
|
|
||||||
|
#define DEF_LANG(name) \
|
||||||
|
std::shared_ptr<void> name##_parse( \
|
||||||
|
std::vector<Token> *tokens, std::shared_ptr<void> in_state, \
|
||||||
|
const char *text, uint32_t len, uint32_t line_num); \
|
||||||
|
bool name##_state_match(std::shared_ptr<void> state_1, \
|
||||||
|
std::shared_ptr<void> state_2);
|
||||||
|
|
||||||
|
#define LANG_A(name) \
|
||||||
|
{ \
|
||||||
|
#name, { name##_parse, name##_state_match } \
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline std::shared_ptr<T> ensure_state(std::shared_ptr<T> state) {
|
||||||
|
using U = typename T::full_state_type;
|
||||||
|
if (!state)
|
||||||
|
state = std::make_shared<T>();
|
||||||
|
if (!state.unique())
|
||||||
|
state = std::make_shared<T>(*state);
|
||||||
|
if (!state->full_state)
|
||||||
|
state->full_state = std::make_shared<U>();
|
||||||
|
else if (!state->full_state.unique())
|
||||||
|
state->full_state = std::make_shared<U>(*state->full_state);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_LANG(ruby);
|
||||||
|
DEF_LANG(bash);
|
||||||
|
|
||||||
|
inline static const std::unordered_map<
|
||||||
|
std::string,
|
||||||
|
std::tuple<std::shared_ptr<void> (*)(
|
||||||
|
std::vector<Token> *tokens, std::shared_ptr<void> in_state,
|
||||||
|
const char *text, uint32_t len, uint32_t line_num),
|
||||||
|
bool (*)(std::shared_ptr<void> state_1,
|
||||||
|
std::shared_ptr<void> state_2)>>
|
||||||
|
parsers = {
|
||||||
|
LANG_A(ruby),
|
||||||
|
LANG_A(bash),
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
245
include/syntax/line_tree.h
Normal file
245
include/syntax/line_tree.h
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
#ifndef LINE_TREE_H
|
||||||
|
#define LINE_TREE_H
|
||||||
|
|
||||||
|
#include "syntax/decl.h"
|
||||||
|
|
||||||
|
struct LineTree {
|
||||||
|
void clear() {
|
||||||
|
std::unique_lock lock(mtx);
|
||||||
|
clear_node(root);
|
||||||
|
root = nullptr;
|
||||||
|
stack_size = 0;
|
||||||
|
}
|
||||||
|
void build(uint32_t x) {
|
||||||
|
std::unique_lock lock(mtx);
|
||||||
|
root = build_node(x);
|
||||||
|
}
|
||||||
|
LineData *at(uint32_t x) {
|
||||||
|
std::shared_lock lock(mtx);
|
||||||
|
LineNode *n = root;
|
||||||
|
while (n) {
|
||||||
|
uint32_t left_size = n->left ? n->left->size : 0;
|
||||||
|
if (x < left_size) {
|
||||||
|
n = n->left;
|
||||||
|
} else if (x < left_size + n->data.size()) {
|
||||||
|
return &n->data[x - left_size];
|
||||||
|
} else {
|
||||||
|
x -= left_size + n->data.size();
|
||||||
|
n = n->right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
LineData *start_iter(uint32_t x) {
|
||||||
|
std::shared_lock lock(mtx);
|
||||||
|
stack_size = 0;
|
||||||
|
LineNode *n = root;
|
||||||
|
while (n) {
|
||||||
|
uint32_t left_size = n->left ? n->left->size : 0;
|
||||||
|
if (x < left_size) {
|
||||||
|
push(n, 0);
|
||||||
|
n = n->left;
|
||||||
|
} else if (x < left_size + n->data.size()) {
|
||||||
|
push(n, x - left_size + 1);
|
||||||
|
return &n->data[x - left_size];
|
||||||
|
} else {
|
||||||
|
x -= left_size + n->data.size();
|
||||||
|
push(n, UINT32_MAX);
|
||||||
|
n = n->right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
void end_iter() { stack_size = 0; }
|
||||||
|
LineData *next() {
|
||||||
|
std::shared_lock lock(mtx);
|
||||||
|
while (stack_size) {
|
||||||
|
auto &f = stack[stack_size - 1];
|
||||||
|
LineNode *n = f.node;
|
||||||
|
if (f.index < n->data.size())
|
||||||
|
return &n->data[f.index++];
|
||||||
|
stack_size--;
|
||||||
|
if (n->right) {
|
||||||
|
n = n->right;
|
||||||
|
while (n) {
|
||||||
|
push(n, 0);
|
||||||
|
if (!n->left)
|
||||||
|
break;
|
||||||
|
n = n->left;
|
||||||
|
}
|
||||||
|
return &stack[stack_size - 1].node->data[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
void insert(uint32_t x, uint32_t y) {
|
||||||
|
std::unique_lock lock(mtx);
|
||||||
|
if (x > subtree_size(root))
|
||||||
|
x = subtree_size(root);
|
||||||
|
root = insert_node(root, x, y);
|
||||||
|
}
|
||||||
|
void erase(uint32_t x, uint32_t y) {
|
||||||
|
std::unique_lock lock(mtx);
|
||||||
|
if (x + y > subtree_size(root))
|
||||||
|
x = subtree_size(root) - y;
|
||||||
|
root = erase_node(root, x, y);
|
||||||
|
}
|
||||||
|
uint32_t count() {
|
||||||
|
std::shared_lock lock(mtx);
|
||||||
|
return subtree_size(root);
|
||||||
|
}
|
||||||
|
~LineTree() { clear(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct LineNode {
|
||||||
|
LineNode *left = nullptr;
|
||||||
|
LineNode *right = nullptr;
|
||||||
|
uint8_t depth = 1;
|
||||||
|
uint32_t size = 0;
|
||||||
|
std::vector<LineData> data;
|
||||||
|
};
|
||||||
|
struct Frame {
|
||||||
|
LineNode *node;
|
||||||
|
uint32_t index;
|
||||||
|
};
|
||||||
|
void push(LineNode *n, uint32_t x) {
|
||||||
|
stack[stack_size].node = n;
|
||||||
|
stack[stack_size].index = x;
|
||||||
|
stack_size++;
|
||||||
|
}
|
||||||
|
static void clear_node(LineNode *n) {
|
||||||
|
if (!n)
|
||||||
|
return;
|
||||||
|
clear_node(n->left);
|
||||||
|
clear_node(n->right);
|
||||||
|
delete n;
|
||||||
|
}
|
||||||
|
LineNode *root = nullptr;
|
||||||
|
Frame stack[32];
|
||||||
|
std::atomic<uint8_t> stack_size = 0;
|
||||||
|
std::shared_mutex mtx;
|
||||||
|
static constexpr uint32_t LEAF_TARGET = 256;
|
||||||
|
LineTree::LineNode *erase_node(LineNode *n, uint32_t x, uint32_t y) {
|
||||||
|
if (!n || y == 0)
|
||||||
|
return n;
|
||||||
|
uint32_t left_sz = subtree_size(n->left);
|
||||||
|
uint32_t mid_sz = n->data.size();
|
||||||
|
if (x < left_sz) {
|
||||||
|
uint32_t len = std::min(y, left_sz - x);
|
||||||
|
n->left = erase_node(n->left, x, len);
|
||||||
|
y -= len;
|
||||||
|
x = left_sz;
|
||||||
|
}
|
||||||
|
if (y > 0 && x < left_sz + mid_sz) {
|
||||||
|
uint32_t mid_x = x - left_sz;
|
||||||
|
uint32_t len = std::min(y, mid_sz - mid_x);
|
||||||
|
n->data.erase(n->data.begin() + mid_x, n->data.begin() + mid_x + len);
|
||||||
|
y -= len;
|
||||||
|
x += len;
|
||||||
|
}
|
||||||
|
if (y > 0) {
|
||||||
|
n->right = erase_node(n->right, x - left_sz - n->data.size(), y);
|
||||||
|
}
|
||||||
|
if (n->left && n->right &&
|
||||||
|
subtree_size(n->left) + subtree_size(n->right) < 256) {
|
||||||
|
return merge(n->left, n->right);
|
||||||
|
}
|
||||||
|
return rebalance(n);
|
||||||
|
}
|
||||||
|
LineTree::LineNode *insert_node(LineNode *n, uint32_t x, uint32_t y) {
|
||||||
|
if (!n) {
|
||||||
|
auto *leaf = new LineNode();
|
||||||
|
leaf->data.resize(y);
|
||||||
|
leaf->size = y;
|
||||||
|
return leaf;
|
||||||
|
}
|
||||||
|
if (!n->left && !n->right) {
|
||||||
|
n->data.insert(n->data.begin() + x, y, LineData());
|
||||||
|
fix(n);
|
||||||
|
if (n->data.size() > 512)
|
||||||
|
return split_leaf(n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
uint32_t left_size = subtree_size(n->left);
|
||||||
|
if (x <= left_size)
|
||||||
|
n->left = insert_node(n->left, x, y);
|
||||||
|
else
|
||||||
|
n->right = insert_node(n->right, x - left_size - n->data.size(), y);
|
||||||
|
return rebalance(n);
|
||||||
|
}
|
||||||
|
LineNode *build_node(uint32_t count) {
|
||||||
|
if (count <= LEAF_TARGET) {
|
||||||
|
auto *n = new LineNode();
|
||||||
|
n->data.resize(count);
|
||||||
|
n->size = count;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
uint32_t left_count = count / 2;
|
||||||
|
uint32_t right_count = count - left_count;
|
||||||
|
auto *n = new LineNode();
|
||||||
|
n->left = build_node(left_count);
|
||||||
|
n->right = build_node(right_count);
|
||||||
|
fix(n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
static LineNode *split_leaf(LineNode *n) {
|
||||||
|
auto *right = new LineNode();
|
||||||
|
size_t mid = n->data.size() / 2;
|
||||||
|
right->data.assign(n->data.begin() + mid, n->data.end());
|
||||||
|
n->data.resize(mid);
|
||||||
|
fix(n);
|
||||||
|
fix(right);
|
||||||
|
auto *parent = new LineNode();
|
||||||
|
parent->left = n;
|
||||||
|
parent->right = right;
|
||||||
|
fix(parent);
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
static LineNode *merge(LineNode *a, LineNode *b) {
|
||||||
|
a->data.insert(a->data.end(), b->data.begin(), b->data.end());
|
||||||
|
delete b;
|
||||||
|
fix(a);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
static void fix(LineNode *n) {
|
||||||
|
n->depth = 1 + MAX(height(n->left), height(n->right));
|
||||||
|
n->size = subtree_size(n->left) + n->data.size() + subtree_size(n->right);
|
||||||
|
}
|
||||||
|
static LineNode *rotate_right(LineNode *y) {
|
||||||
|
LineNode *x = y->left;
|
||||||
|
LineNode *T2 = x->right;
|
||||||
|
x->right = y;
|
||||||
|
y->left = T2;
|
||||||
|
fix(y);
|
||||||
|
fix(x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
static LineNode *rotate_left(LineNode *x) {
|
||||||
|
LineNode *y = x->right;
|
||||||
|
LineNode *T2 = y->left;
|
||||||
|
y->left = x;
|
||||||
|
x->right = T2;
|
||||||
|
fix(x);
|
||||||
|
fix(y);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
static LineNode *rebalance(LineNode *n) {
|
||||||
|
fix(n);
|
||||||
|
int balance = int(height(n->left)) - int(height(n->right));
|
||||||
|
if (balance > 1) {
|
||||||
|
if (height(n->left->left) < height(n->left->right))
|
||||||
|
n->left = rotate_left(n->left);
|
||||||
|
return rotate_right(n);
|
||||||
|
}
|
||||||
|
if (balance < -1) {
|
||||||
|
if (height(n->right->right) < height(n->right->left))
|
||||||
|
n->right = rotate_right(n->right);
|
||||||
|
return rotate_left(n);
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
static uint8_t height(LineNode *n) { return n ? n->depth : 0; }
|
||||||
|
static uint32_t subtree_size(LineNode *n) { return n ? n->size : 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
33
include/syntax/parser.h
Normal file
33
include/syntax/parser.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef SYNTAX_PARSER_H
|
||||||
|
#define SYNTAX_PARSER_H
|
||||||
|
|
||||||
|
#include "scripting/decl.h"
|
||||||
|
#include "syntax/decl.h"
|
||||||
|
#include "syntax/line_tree.h"
|
||||||
|
|
||||||
|
struct Parser {
|
||||||
|
struct Editor *editor = nullptr;
|
||||||
|
std::string lang;
|
||||||
|
std::shared_ptr<void> (*parse_func)(std::vector<Token> *tokens,
|
||||||
|
std::shared_ptr<void> in_state,
|
||||||
|
const char *text, uint32_t len,
|
||||||
|
uint32_t line_num);
|
||||||
|
bool (*state_match_func)(std::shared_ptr<void> state_1,
|
||||||
|
std::shared_ptr<void> state_2);
|
||||||
|
mrb_value parser_block = mrb_nil_value();
|
||||||
|
mrb_value match_block = mrb_nil_value();
|
||||||
|
bool is_custom{false};
|
||||||
|
std::atomic<uint32_t> scroll_max{UINT32_MAX - 2048};
|
||||||
|
std::atomic<bool> scroll_dirty{false};
|
||||||
|
std::mutex mutex;
|
||||||
|
std::mutex data_mutex;
|
||||||
|
LineTree line_tree;
|
||||||
|
UniqueQueue<uint32_t> dirty_lines;
|
||||||
|
|
||||||
|
Parser(Editor *editor, std::string n_lang, uint32_t n_scroll_max);
|
||||||
|
void edit(uint32_t start_line, uint32_t old_end_line, uint32_t inserted_rows);
|
||||||
|
void work();
|
||||||
|
void scroll(uint32_t line);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
53
include/syntax/tokens.def
Normal file
53
include/syntax/tokens.def
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
ADD(K_DATA)
|
||||||
|
ADD(K_SHEBANG)
|
||||||
|
ADD(K_COMMENT)
|
||||||
|
ADD(K_ERROR)
|
||||||
|
ADD(K_STRING)
|
||||||
|
ADD(K_ESCAPE)
|
||||||
|
ADD(K_INTERPOLATION)
|
||||||
|
ADD(K_REGEXP)
|
||||||
|
ADD(K_NUMBER)
|
||||||
|
ADD(K_TRUE)
|
||||||
|
ADD(K_FALSE)
|
||||||
|
ADD(K_CHAR)
|
||||||
|
ADD(K_KEYWORD)
|
||||||
|
ADD(K_KEYWORDOPERATOR)
|
||||||
|
ADD(K_OPERATOR)
|
||||||
|
ADD(K_FUNCTION)
|
||||||
|
ADD(K_TYPE)
|
||||||
|
ADD(K_CONSTANT)
|
||||||
|
ADD(K_VARIABLEINSTANCE)
|
||||||
|
ADD(K_VARIABLEGLOBAL)
|
||||||
|
ADD(K_ANNOTATION)
|
||||||
|
ADD(K_DIRECTIVE)
|
||||||
|
ADD(K_LABEL)
|
||||||
|
ADD(K_BRACE1)
|
||||||
|
ADD(K_BRACE2)
|
||||||
|
ADD(K_BRACE3)
|
||||||
|
ADD(K_BRACE4)
|
||||||
|
ADD(K_BRACE5)
|
||||||
|
ADD(K_HEADING1)
|
||||||
|
ADD(K_HEADING2)
|
||||||
|
ADD(K_HEADING3)
|
||||||
|
ADD(K_HEADING4)
|
||||||
|
ADD(K_HEADING5)
|
||||||
|
ADD(K_HEADING6)
|
||||||
|
ADD(K_BLOCKQUOTE)
|
||||||
|
ADD(K_LIST)
|
||||||
|
ADD(K_LISTITEM)
|
||||||
|
ADD(K_CODE)
|
||||||
|
ADD(K_LANGUAGENAME)
|
||||||
|
ADD(K_LINKLABEL)
|
||||||
|
ADD(K_IMAGELABEL)
|
||||||
|
ADD(K_LINK)
|
||||||
|
ADD(K_TABLE)
|
||||||
|
ADD(K_TABLEHEADER)
|
||||||
|
ADD(K_ITALIC)
|
||||||
|
ADD(K_BOLD)
|
||||||
|
ADD(K_UNDERLINE)
|
||||||
|
ADD(K_STRIKETHROUGH)
|
||||||
|
ADD(K_HORIXONTALRULE)
|
||||||
|
ADD(K_TAG)
|
||||||
|
ADD(K_ATTRIBUTE)
|
||||||
|
ADD(K_CHECKDONE)
|
||||||
|
ADD(K_CHECKNOTDONE)
|
||||||
140
include/syntax/trie.h
Normal file
140
include/syntax/trie.h
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
#ifndef SYNTAX_TRIE_H
|
||||||
|
#define SYNTAX_TRIE_H
|
||||||
|
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
template <typename T> struct Trie {
|
||||||
|
struct TrieNode {
|
||||||
|
bool is_word = false;
|
||||||
|
std::array<TrieNode *, 128> children{};
|
||||||
|
std::conditional_t<std::is_void_v<T>, char, std::optional<T>> value;
|
||||||
|
TrieNode() { children.fill(nullptr); }
|
||||||
|
};
|
||||||
|
|
||||||
|
Trie() {}
|
||||||
|
~Trie() { clear_trie(root); }
|
||||||
|
|
||||||
|
void build(const std::vector<std::string> &words, bool cs = true) {
|
||||||
|
static_assert(std::is_void_v<T>, "This build() is for Trie<void> only");
|
||||||
|
case_sensitive = cs;
|
||||||
|
for (auto &w : words)
|
||||||
|
insert(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U = T>
|
||||||
|
std::enable_if_t<!std::is_void_v<U>>
|
||||||
|
build(const std::vector<std::pair<std::string, U>> &words, bool cs = true) {
|
||||||
|
static_assert(!std::is_void_v<T>, "This build() is for typed Trie only");
|
||||||
|
case_sensitive = cs;
|
||||||
|
for (auto &[w, v] : words)
|
||||||
|
insert(w, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t match(const char *text, uint32_t pos, uint32_t len,
|
||||||
|
bool (*is_word_char)(char c)) const {
|
||||||
|
const TrieNode *node = root;
|
||||||
|
uint32_t max_len = 0;
|
||||||
|
for (uint32_t i = pos; i < len; ++i) {
|
||||||
|
unsigned char uc = static_cast<unsigned char>(text[i]);
|
||||||
|
if (uc >= 128)
|
||||||
|
return 0;
|
||||||
|
if (!case_sensitive && uc >= 'A' && uc <= 'Z')
|
||||||
|
uc = uc - 'A' + 'a';
|
||||||
|
if (!node->children[uc]) {
|
||||||
|
if (node->is_word && !is_word_char(text[i]))
|
||||||
|
return i - pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
node = node->children[uc];
|
||||||
|
if (node->is_word)
|
||||||
|
max_len = i - pos + 1;
|
||||||
|
}
|
||||||
|
if (max_len > 0)
|
||||||
|
if (pos + max_len < len && is_word_char(text[pos + max_len]))
|
||||||
|
return 0;
|
||||||
|
return max_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U = T>
|
||||||
|
uint32_t
|
||||||
|
match(const char *text, uint32_t pos, uint32_t len,
|
||||||
|
bool (*is_word_char)(char c),
|
||||||
|
std::conditional_t<std::is_void_v<T>, void *, std::optional<T> *>
|
||||||
|
out_val = nullptr) const {
|
||||||
|
const TrieNode *node = root;
|
||||||
|
const TrieNode *last_word_node = nullptr;
|
||||||
|
uint32_t max_len = 0;
|
||||||
|
for (uint32_t i = pos; i < len; ++i) {
|
||||||
|
unsigned char uc = static_cast<unsigned char>(text[i]);
|
||||||
|
if (uc >= 128)
|
||||||
|
break;
|
||||||
|
if (!case_sensitive && uc >= 'A' && uc <= 'Z')
|
||||||
|
uc = uc - 'A' + 'a';
|
||||||
|
if (!node->children[uc])
|
||||||
|
break;
|
||||||
|
node = node->children[uc];
|
||||||
|
if (node->is_word) {
|
||||||
|
last_word_node = node;
|
||||||
|
max_len = i - pos + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!last_word_node) {
|
||||||
|
if (out_val)
|
||||||
|
*out_val = std::nullopt;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (pos + max_len < len && is_word_char(text[pos + max_len])) {
|
||||||
|
if (out_val)
|
||||||
|
*out_val = std::nullopt;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (out_val)
|
||||||
|
*out_val = last_word_node->value;
|
||||||
|
return max_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
TrieNode *root = new TrieNode();
|
||||||
|
bool case_sensitive = true;
|
||||||
|
|
||||||
|
void insert(const std::string &word) {
|
||||||
|
TrieNode *node = root;
|
||||||
|
for (char c : word) {
|
||||||
|
unsigned char uc = static_cast<unsigned char>(c);
|
||||||
|
if (uc >= 128)
|
||||||
|
return;
|
||||||
|
if (!case_sensitive && uc >= 'A' && uc <= 'Z')
|
||||||
|
uc = uc - 'A' + 'a';
|
||||||
|
if (!node->children[uc])
|
||||||
|
node->children[uc] = new TrieNode();
|
||||||
|
node = node->children[uc];
|
||||||
|
}
|
||||||
|
node->is_word = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U = T>
|
||||||
|
std::enable_if_t<!std::is_void_v<U>> insert(const std::string &word,
|
||||||
|
const U &val) {
|
||||||
|
TrieNode *node = root;
|
||||||
|
for (char c : word) {
|
||||||
|
unsigned char uc = static_cast<unsigned char>(c);
|
||||||
|
if (!case_sensitive && uc >= 'A' && uc <= 'Z')
|
||||||
|
uc = uc - 'A' + 'a';
|
||||||
|
if (!node->children[uc])
|
||||||
|
node->children[uc] = new TrieNode();
|
||||||
|
node = node->children[uc];
|
||||||
|
}
|
||||||
|
node->is_word = true;
|
||||||
|
node->value = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_trie(TrieNode *node) {
|
||||||
|
if (!node)
|
||||||
|
return;
|
||||||
|
for (auto *child : node->children)
|
||||||
|
clear_trie(child);
|
||||||
|
delete node;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
16
include/ts.h
16
include/ts.h
@@ -1,16 +0,0 @@
|
|||||||
#ifndef TS_H
|
|
||||||
#define TS_H
|
|
||||||
|
|
||||||
#include "./editor.h"
|
|
||||||
#include "./utils.h"
|
|
||||||
#include <pcre2.h>
|
|
||||||
|
|
||||||
#define HEX(s) (static_cast<uint32_t>(std::stoul(s, nullptr, 16)))
|
|
||||||
|
|
||||||
extern std::unordered_map<std::string, pcre2_code *> regex_cache;
|
|
||||||
|
|
||||||
TSQuery *load_query(const char *query_path, Editor *editor);
|
|
||||||
void ts_collect_spans(Editor *editor);
|
|
||||||
void clear_regex_cache();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#include "../libs/tree-sitter/lib/include/tree_sitter/api.h"
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
struct Language {
|
|
||||||
std::string name;
|
|
||||||
const TSLanguage *(*fn)();
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
const TSLanguage *tree_sitter_bash();
|
|
||||||
const TSLanguage *tree_sitter_c();
|
|
||||||
const TSLanguage *tree_sitter_cpp();
|
|
||||||
const TSLanguage *tree_sitter_css();
|
|
||||||
const TSLanguage *tree_sitter_fish();
|
|
||||||
const TSLanguage *tree_sitter_go();
|
|
||||||
const TSLanguage *tree_sitter_haskell();
|
|
||||||
const TSLanguage *tree_sitter_html();
|
|
||||||
const TSLanguage *tree_sitter_javascript();
|
|
||||||
const TSLanguage *tree_sitter_json();
|
|
||||||
const TSLanguage *tree_sitter_lua();
|
|
||||||
const TSLanguage *tree_sitter_make();
|
|
||||||
const TSLanguage *tree_sitter_python();
|
|
||||||
const TSLanguage *tree_sitter_ruby();
|
|
||||||
}
|
|
||||||
105
include/ui.h
105
include/ui.h
@@ -1,105 +0,0 @@
|
|||||||
#ifndef UI_H
|
|
||||||
#define UI_H
|
|
||||||
|
|
||||||
#include "./utils.h"
|
|
||||||
#include <atomic>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <mutex>
|
|
||||||
#include <string.h>
|
|
||||||
#include <string>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <termios.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#define KEY_CHAR 0
|
|
||||||
#define KEY_SPECIAL 1
|
|
||||||
#define KEY_MOUSE 2
|
|
||||||
#define KEY_NONE 3
|
|
||||||
|
|
||||||
#define KEY_UP 0
|
|
||||||
#define KEY_DOWN 1
|
|
||||||
#define KEY_LEFT 2
|
|
||||||
#define KEY_RIGHT 3
|
|
||||||
#define KEY_DELETE 4
|
|
||||||
|
|
||||||
#define KEY_ESC '\x1b'
|
|
||||||
|
|
||||||
#define PRESS 0
|
|
||||||
#define RELEASE 1
|
|
||||||
#define DRAG 2
|
|
||||||
#define SCROLL 3
|
|
||||||
|
|
||||||
#define LEFT_BTN 0
|
|
||||||
#define MIDDLE_BTN 1
|
|
||||||
#define RIGHT_BTN 2
|
|
||||||
#define SCROLL_BTN 3
|
|
||||||
#define NONE_BTN 4
|
|
||||||
|
|
||||||
#define SCROLL_UP 0
|
|
||||||
#define SCROLL_DOWN 1
|
|
||||||
#define SCROLL_LEFT 2
|
|
||||||
#define SCROLL_RIGHT 3
|
|
||||||
|
|
||||||
#define ALT 1
|
|
||||||
#define CNTRL 2
|
|
||||||
#define CNTRL_ALT 3
|
|
||||||
#define SHIFT 4
|
|
||||||
|
|
||||||
const char VS16_BYTE_A = '\xEF';
|
|
||||||
const char VS16_BYTE_B = '\xB8';
|
|
||||||
const char VS16_BYTE_C = '\x8F';
|
|
||||||
|
|
||||||
enum CellFlags : uint8_t {
|
|
||||||
CF_NONE = 0,
|
|
||||||
CF_ITALIC = 1 << 0,
|
|
||||||
CF_BOLD = 1 << 1,
|
|
||||||
CF_UNDERLINE = 1 << 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ScreenCell {
|
|
||||||
std::string utf8 = std::string(""); // empty => no content
|
|
||||||
uint32_t fg = 0;
|
|
||||||
uint32_t bg = 0;
|
|
||||||
uint8_t flags = CF_NONE;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KeyEvent {
|
|
||||||
uint8_t key_type;
|
|
||||||
|
|
||||||
char c;
|
|
||||||
|
|
||||||
uint8_t special_key;
|
|
||||||
uint8_t special_modifier;
|
|
||||||
|
|
||||||
uint8_t mouse_x;
|
|
||||||
uint8_t mouse_y;
|
|
||||||
uint8_t mouse_button;
|
|
||||||
uint8_t mouse_state;
|
|
||||||
uint8_t mouse_direction;
|
|
||||||
uint8_t mouse_modifier;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern uint32_t rows, cols;
|
|
||||||
extern std::vector<ScreenCell> screen; // size rows*cols
|
|
||||||
extern std::vector<ScreenCell> old_screen;
|
|
||||||
extern std::mutex screen_mutex;
|
|
||||||
extern std::atomic<bool> running;
|
|
||||||
|
|
||||||
void get_terminal_size();
|
|
||||||
void enable_raw_mode();
|
|
||||||
void disable_raw_mode();
|
|
||||||
Coord start_screen();
|
|
||||||
void end_screen();
|
|
||||||
void update(uint32_t row, uint32_t col, const char *utf8, uint32_t fg,
|
|
||||||
uint32_t bg, uint8_t flags);
|
|
||||||
void set_cursor(int row, int col, int show_cursor_param);
|
|
||||||
void render();
|
|
||||||
Coord get_size();
|
|
||||||
|
|
||||||
int read_input(char *buf, size_t buflen);
|
|
||||||
KeyEvent read_key();
|
|
||||||
|
|
||||||
int display_width(const char *str);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
23
include/ui/bar.h
Normal file
23
include/ui/bar.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef UI_BAR_H
|
||||||
|
#define UI_BAR_H
|
||||||
|
|
||||||
|
#include "editor/editor.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
Coord screen;
|
||||||
|
std::string command = "";
|
||||||
|
std::string log_line = "";
|
||||||
|
uint32_t cursor = 0;
|
||||||
|
BarLine bar_line;
|
||||||
|
std::mutex mtx;
|
||||||
|
|
||||||
|
void init(Coord screen) { this->screen = screen; }
|
||||||
|
void work();
|
||||||
|
void render();
|
||||||
|
void handle(KeyEvent event);
|
||||||
|
void log(std::string message);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
21
include/ui/completionbox.h
Normal file
21
include/ui/completionbox.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef UI_COMPLETIONBOX_H
|
||||||
|
#define UI_COMPLETIONBOX_H
|
||||||
|
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "pch.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
struct CompletionBox {
|
||||||
|
std::shared_mutex mtx;
|
||||||
|
struct CompletionSession *session;
|
||||||
|
bool hidden = true;
|
||||||
|
std::vector<ScreenCell> cells;
|
||||||
|
Coord size;
|
||||||
|
Coord position;
|
||||||
|
|
||||||
|
CompletionBox(CompletionSession *s) : session(s) {}
|
||||||
|
void render_update();
|
||||||
|
void render(Coord pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
19
include/ui/diagnostics.h
Normal file
19
include/ui/diagnostics.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef UI_DIAGNOSTICS_H
|
||||||
|
#define UI_DIAGNOSTICS_H
|
||||||
|
|
||||||
|
#include "editor/decl.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "pch.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
struct DiagnosticBox {
|
||||||
|
std::vector<VWarn> warnings;
|
||||||
|
std::vector<ScreenCell> cells;
|
||||||
|
Coord size;
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
void render_first();
|
||||||
|
void render(Coord pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
22
include/ui/hover.h
Normal file
22
include/ui/hover.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#ifndef UI_HOVER_H
|
||||||
|
#define UI_HOVER_H
|
||||||
|
|
||||||
|
#include "editor/decl.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "pch.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
struct HoverBox {
|
||||||
|
std::string text;
|
||||||
|
std::atomic<bool> is_markup;
|
||||||
|
uint32_t scroll_;
|
||||||
|
std::vector<ScreenCell> cells;
|
||||||
|
Coord size;
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
void scroll(int32_t number);
|
||||||
|
void render_first(bool scroll = false);
|
||||||
|
void render(Coord pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
#ifndef UTILS_H
|
|
||||||
#define UTILS_H
|
|
||||||
|
|
||||||
#include "./ts_def.h"
|
|
||||||
#include <mutex>
|
|
||||||
#include <queue>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
|
||||||
#define PCRE_WORKSPACE_SIZE 512
|
|
||||||
|
|
||||||
template <typename T> struct Queue {
|
|
||||||
std::queue<T> q;
|
|
||||||
std::mutex m;
|
|
||||||
|
|
||||||
void push(T val) {
|
|
||||||
std::lock_guard<std::mutex> lock(m);
|
|
||||||
q.push(val);
|
|
||||||
}
|
|
||||||
bool pop(T &val) {
|
|
||||||
std::lock_guard<std::mutex> lock(m);
|
|
||||||
if (q.empty())
|
|
||||||
return false;
|
|
||||||
val = q.front();
|
|
||||||
q.pop();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool empty() {
|
|
||||||
std::lock_guard<std::mutex> lock(m);
|
|
||||||
return q.empty();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Coord {
|
|
||||||
uint32_t row;
|
|
||||||
uint32_t col;
|
|
||||||
};
|
|
||||||
|
|
||||||
uint32_t grapheme_strlen(const char *s);
|
|
||||||
uint32_t get_visual_col_from_bytes(const char *line, uint32_t byte_limit);
|
|
||||||
uint32_t get_bytes_from_visual_col(const char *line,
|
|
||||||
uint32_t target_visual_col);
|
|
||||||
void log(const char *fmt, ...);
|
|
||||||
std::string get_exe_dir();
|
|
||||||
char *load_file(const char *path, uint32_t *out_len);
|
|
||||||
char *detect_file_type(const char *filename);
|
|
||||||
Language language_for_file(const char *filename);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
188
include/utils/utils.h
Normal file
188
include/utils/utils.h
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
#ifndef UTILS_H
|
||||||
|
#define UTILS_H
|
||||||
|
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
template <typename T> struct Queue {
|
||||||
|
void push(T val) {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
q.push(val);
|
||||||
|
}
|
||||||
|
std::optional<T> front() {
|
||||||
|
if (q.empty())
|
||||||
|
return std::nullopt;
|
||||||
|
return q.front();
|
||||||
|
}
|
||||||
|
bool pop(T &val) {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
if (q.empty())
|
||||||
|
return false;
|
||||||
|
val = q.front();
|
||||||
|
q.pop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void pop() {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
q.pop();
|
||||||
|
}
|
||||||
|
bool empty() {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
return q.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::queue<T> q;
|
||||||
|
std::mutex m;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> struct UniqueQueue {
|
||||||
|
bool push(const T &value) {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
if (set.contains(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dq.push_back(value);
|
||||||
|
set.insert(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool pop(T &out) {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
if (dq.empty())
|
||||||
|
return false;
|
||||||
|
out = dq.front();
|
||||||
|
dq.pop_front();
|
||||||
|
set.erase(out);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool empty() const {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
return dq.empty();
|
||||||
|
}
|
||||||
|
void clear() {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
dq.clear();
|
||||||
|
set.clear();
|
||||||
|
}
|
||||||
|
size_t size() const {
|
||||||
|
std::lock_guard<std::mutex> lock(m);
|
||||||
|
return dq.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::deque<T> dq;
|
||||||
|
std::set<T> set;
|
||||||
|
mutable std::mutex m;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Coord {
|
||||||
|
uint32_t row;
|
||||||
|
uint32_t col;
|
||||||
|
|
||||||
|
bool operator<(const Coord &other) const {
|
||||||
|
return row < other.row || (row == other.row && col < other.col);
|
||||||
|
}
|
||||||
|
bool operator<=(const Coord &other) const {
|
||||||
|
return *this < other || *this == other;
|
||||||
|
}
|
||||||
|
bool operator==(const Coord &other) const {
|
||||||
|
return row == other.row && col == other.col;
|
||||||
|
}
|
||||||
|
bool operator!=(const Coord &other) const { return !(*this == other); }
|
||||||
|
bool operator>(const Coord &other) const { return other < *this; }
|
||||||
|
bool operator>=(const Coord &other) const { return !(*this < other); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Match {
|
||||||
|
size_t start;
|
||||||
|
size_t end;
|
||||||
|
std::string text;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Language {
|
||||||
|
std::string name;
|
||||||
|
std::string lsp_name;
|
||||||
|
uint32_t color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LSP {
|
||||||
|
std::string command;
|
||||||
|
std::vector<std::string> args;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern std::unordered_map<std::string, Language> languages;
|
||||||
|
extern std::unordered_map<std::string, std::string> language_extensions;
|
||||||
|
extern std::unordered_map<std::string, LSP> lsps;
|
||||||
|
|
||||||
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
#define ABS(x) ((x) < 0 ? -(x) : (x))
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
|
#define USING(x) UNUSED(sizeof(x))
|
||||||
|
|
||||||
|
inline uint32_t HEX(const std::string &s) {
|
||||||
|
if (s.empty())
|
||||||
|
return 0xFFFFFF;
|
||||||
|
size_t start = (s.front() == '#') ? 1 : 0;
|
||||||
|
return static_cast<uint32_t>(std::stoul(s.substr(start), nullptr, 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool compare(const char *a, const char *b, size_t n);
|
||||||
|
std::string clean_text(const std::string &input);
|
||||||
|
std::string percent_encode(const std::string &s);
|
||||||
|
std::string percent_decode(const std::string &s);
|
||||||
|
uint32_t count_clusters(const char *line, size_t len, size_t from, size_t to);
|
||||||
|
std::string trim(const std::string &s);
|
||||||
|
std::string substitute_fence(const std::string &documentation,
|
||||||
|
const std::string &lang);
|
||||||
|
|
||||||
|
int display_width(const char *str, size_t len);
|
||||||
|
uint32_t get_visual_col_from_bytes(const char *line, uint32_t len,
|
||||||
|
uint32_t byte_limit);
|
||||||
|
uint32_t get_bytes_from_visual_col(const char *line, uint32_t len,
|
||||||
|
uint32_t target_visual_col);
|
||||||
|
size_t utf8_offset_to_utf16(const char *utf8, size_t utf8_len,
|
||||||
|
size_t byte_offset);
|
||||||
|
size_t utf16_offset_to_utf8(const char *utf8, size_t utf8_len,
|
||||||
|
size_t utf16_offset);
|
||||||
|
uint8_t utf8_codepoint_width(unsigned char c);
|
||||||
|
|
||||||
|
void log(const char *fmt, ...);
|
||||||
|
|
||||||
|
std::string path_abs(const std::string &path_str);
|
||||||
|
std::string path_to_file_uri(const std::string &path_str);
|
||||||
|
std::string filename_from_path(const std::string &path);
|
||||||
|
std::string get_exe_dir();
|
||||||
|
char *load_file(const char *path, uint32_t *out_len, bool *out_eol);
|
||||||
|
Language language_for_file(const char *filename);
|
||||||
|
|
||||||
|
void copy_to_clipboard(const char *text, size_t len);
|
||||||
|
char *get_from_clipboard(uint32_t *out_len);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T *safe_get(std::map<uint16_t, T> &m, uint16_t key) {
|
||||||
|
auto it = m.find(key);
|
||||||
|
if (it == m.end())
|
||||||
|
return nullptr;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Func, typename... Args>
|
||||||
|
auto throttle(std::chrono::milliseconds min_duration, Func &&func,
|
||||||
|
Args &&...args) {
|
||||||
|
auto start = std::chrono::steady_clock::now();
|
||||||
|
if constexpr (std::is_void_v<std::invoke_result_t<Func, Args...>>) {
|
||||||
|
std::invoke(std::forward<Func>(func), std::forward<Args>(args)...);
|
||||||
|
} else {
|
||||||
|
auto result =
|
||||||
|
std::invoke(std::forward<Func>(func), std::forward<Args>(args)...);
|
||||||
|
auto elapsed = std::chrono::steady_clock::now() - start;
|
||||||
|
if (elapsed < min_duration)
|
||||||
|
std::this_thread::sleep_for(min_duration - elapsed);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
auto elapsed = std::chrono::steady_clock::now() - start;
|
||||||
|
if (elapsed < min_duration)
|
||||||
|
std::this_thread::sleep_for(min_duration - elapsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
39
installer.sh
Normal file
39
installer.sh
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
install() {
|
||||||
|
BINARY_NAME="crib"
|
||||||
|
BIN_URL="https://git.syedm.dev/SyedM/crib/releases/download/v0.0.2-alpha/crib"
|
||||||
|
|
||||||
|
echo "Install or update locally (~/.local/bin) or globally (/usr/bin)? [l/g]"
|
||||||
|
read -r choice </dev/tty
|
||||||
|
case "$choice" in
|
||||||
|
l | L)
|
||||||
|
INSTALL_DIR="$HOME/.local/bin"
|
||||||
|
SUDO=""
|
||||||
|
;;
|
||||||
|
g | G)
|
||||||
|
INSTALL_DIR="/usr/bin"
|
||||||
|
SUDO="sudo"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid choice"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
$SUDO mkdir -p "$INSTALL_DIR"
|
||||||
|
|
||||||
|
echo "Downloading binary..."
|
||||||
|
curl -L "$BIN_URL" -o /tmp/"$BINARY_NAME"
|
||||||
|
$SUDO install -m 755 /tmp/"$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
|
||||||
|
rm -f /tmp/"$BINARY_NAME"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "✔ Crib installed to $INSTALL_DIR"
|
||||||
|
echo "Run with: $BINARY_NAME"
|
||||||
|
echo "Add $INSTALL_DIR to PATH if needed."
|
||||||
|
}
|
||||||
|
|
||||||
|
install "$@"
|
||||||
1
libs/tree-sitter
vendored
1
libs/tree-sitter
vendored
Submodule libs/tree-sitter deleted from 0ca8fe8c12
1
libs/tree-sitter-bash
vendored
1
libs/tree-sitter-bash
vendored
Submodule libs/tree-sitter-bash deleted from a06c2e4415
1
libs/tree-sitter-c
vendored
1
libs/tree-sitter-c
vendored
Submodule libs/tree-sitter-c deleted from ae19b676b1
1
libs/tree-sitter-cpp
vendored
1
libs/tree-sitter-cpp
vendored
Submodule libs/tree-sitter-cpp deleted from 12bd6f7e96
1
libs/tree-sitter-css
vendored
1
libs/tree-sitter-css
vendored
Submodule libs/tree-sitter-css deleted from dda5cfc572
1
libs/tree-sitter-fish
vendored
1
libs/tree-sitter-fish
vendored
Submodule libs/tree-sitter-fish deleted from aa074a0bac
1
libs/tree-sitter-go
vendored
1
libs/tree-sitter-go
vendored
Submodule libs/tree-sitter-go deleted from 2346a3ab1b
1
libs/tree-sitter-haskell
vendored
1
libs/tree-sitter-haskell
vendored
Submodule libs/tree-sitter-haskell deleted from 0975ef72fc
1
libs/tree-sitter-html
vendored
1
libs/tree-sitter-html
vendored
Submodule libs/tree-sitter-html deleted from 73a3947324
1
libs/tree-sitter-javascript
vendored
1
libs/tree-sitter-javascript
vendored
Submodule libs/tree-sitter-javascript deleted from 58404d8cf1
1
libs/tree-sitter-json
vendored
1
libs/tree-sitter-json
vendored
Submodule libs/tree-sitter-json deleted from 001c28d7a2
1
libs/tree-sitter-lua
vendored
1
libs/tree-sitter-lua
vendored
Submodule libs/tree-sitter-lua deleted from d76023017f
1
libs/tree-sitter-make
vendored
1
libs/tree-sitter-make
vendored
Submodule libs/tree-sitter-make deleted from 5e9e8f8ff3
1
libs/tree-sitter-python
vendored
1
libs/tree-sitter-python
vendored
Submodule libs/tree-sitter-python deleted from 26855eabcc
1
libs/tree-sitter-ruby
vendored
1
libs/tree-sitter-ruby
vendored
Submodule libs/tree-sitter-ruby deleted from 89bd7a8e54
119
samples/Makefile
Normal file
119
samples/Makefile
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
SRC_DIR := src
|
||||||
|
BIN_DIR := bin
|
||||||
|
OBJ_DIR := build
|
||||||
|
INCLUDE_DIR := include
|
||||||
|
|
||||||
|
TARGET_DEBUG := $(BIN_DIR)/crib-dbg
|
||||||
|
TARGET_RELEASE := $(BIN_DIR)/crib
|
||||||
|
|
||||||
|
PCH_DEBUG := $(OBJ_DIR)/debug/pch.h.gch
|
||||||
|
PCH_RELEASE := $(OBJ_DIR)/release/pch.h.gch
|
||||||
|
|
||||||
|
CCACHE := ccache
|
||||||
|
CXX_DEBUG := $(CCACHE) g++
|
||||||
|
CXX_RELEASE := $(CCACHE) clang++
|
||||||
|
|
||||||
|
CFLAGS_DEBUG := -std=c++20 -Wall -Wextra -O0 -fno-inline -gsplit-dwarf -g -fsanitize=address -fno-omit-frame-pointer
|
||||||
|
CFLAGS_RELEASE := -std=c++20 -O3 -march=native -flto=thin \
|
||||||
|
-fno-exceptions -fno-rtti -fstrict-aliasing \
|
||||||
|
-ffast-math -funroll-loops \
|
||||||
|
-fvisibility=hidden \
|
||||||
|
-fomit-frame-pointer -DNDEBUG -s \
|
||||||
|
-mllvm -vectorize-loops \
|
||||||
|
-fno-unwind-tables -fno-asynchronous-unwind-tables
|
||||||
|
|
||||||
|
PCH_CFLAGS_DEBUG := $(CFLAGS_DEBUG) -x c++-header
|
||||||
|
PCH_CFLAGS_RELEASE := $(CFLAGS_RELEASE) -x c++-header
|
||||||
|
|
||||||
|
UNICODE_SRC := $(wildcard libs/unicode_width/*.c)
|
||||||
|
|
||||||
|
UNICODE_OBJ_DEBUG := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/debug/unicode_width/%.o,$(UNICODE_SRC))
|
||||||
|
UNICODE_OBJ_RELEASE := $(patsubst libs/unicode_width/%.c,$(OBJ_DIR)/release/unicode_width/%.o,$(UNICODE_SRC))
|
||||||
|
|
||||||
|
TREE_SITTER_LIBS := $(wildcard libs/tree-sitter-*/libtree-sitter*.a)
|
||||||
|
|
||||||
|
PHP_LIB := libs/tree-sitter-php/php/libtree-sitter-php.a
|
||||||
|
|
||||||
|
NGINX_OBJ_PARSER := libs/tree-sitter-nginx/build/Release/obj.target/tree_sitter_nginx_binding/src/parser.o
|
||||||
|
|
||||||
|
GITIGNORE_OBJ_PARSER := libs/tree-sitter-gitignore/build/Release/obj.target/tree_sitter_ignore_binding/src/parser.o
|
||||||
|
|
||||||
|
FISH_OBJ_PARSER := libs/tree-sitter-fish/build/Release/obj.target/tree_sitter_fish_binding/src/parser.o
|
||||||
|
FISH_OBJ_SCANNER := libs/tree-sitter-fish/build/Release/obj.target/tree_sitter_fish_binding/src/scanner.o
|
||||||
|
|
||||||
|
MD_OBJ_PARSER := libs/tree-sitter-markdown/build/Release/obj.target/tree_sitter_markdown_binding/tree-sitter-markdown/src/parser.o
|
||||||
|
MD_OBJ_SCANNER := libs/tree-sitter-markdown/build/Release/obj.target/tree_sitter_markdown_binding/tree-sitter-markdown/src/scanner.o
|
||||||
|
|
||||||
|
MD_I_OBJ_PARSER := libs/tree-sitter-markdown/build/Release/obj.target/tree_sitter_markdown_binding/tree-sitter-markdown-inline/src/parser.o
|
||||||
|
MD_I_OBJ_SCANNER := libs/tree-sitter-markdown/build/Release/obj.target/tree_sitter_markdown_binding/tree-sitter-markdown-inline/src/scanner.o
|
||||||
|
|
||||||
|
LIBS := \
|
||||||
|
libs/libgrapheme/libgrapheme.a \
|
||||||
|
libs/tree-sitter/libtree-sitter.a \
|
||||||
|
$(TREE_SITTER_LIBS) \
|
||||||
|
$(PHP_LIB) \
|
||||||
|
$(NGINX_OBJ_PARSER) \
|
||||||
|
$(GITIGNORE_OBJ_PARSER) \
|
||||||
|
$(FISH_OBJ_PARSER) \
|
||||||
|
$(FISH_OBJ_SCANNER) \
|
||||||
|
$(MD_OBJ_PARSER) \
|
||||||
|
$(MD_OBJ_SCANNER) \
|
||||||
|
$(MD_I_OBJ_PARSER) \
|
||||||
|
$(MD_I_OBJ_SCANNER) \
|
||||||
|
-lpcre2-8 -lmagic
|
||||||
|
|
||||||
|
SRC := $(wildcard $(SRC_DIR)/*.cc)
|
||||||
|
OBJ_DEBUG := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/debug/%.o,$(SRC))
|
||||||
|
OBJ_RELEASE := $(patsubst $(SRC_DIR)/%.cc,$(OBJ_DIR)/release/%.o,$(SRC))
|
||||||
|
|
||||||
|
DEP_DEBUG := $(OBJ_DEBUG:.o=.d)
|
||||||
|
DEP_RELEASE := $(OBJ_RELEASE:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all test release clean
|
||||||
|
|
||||||
|
all: debug
|
||||||
|
|
||||||
|
test: $(TARGET_DEBUG)
|
||||||
|
|
||||||
|
release: $(TARGET_RELEASE)
|
||||||
|
|
||||||
|
$(PCH_DEBUG): $(INCLUDE_DIR)/pch.h
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CXX_DEBUG) $(PCH_CFLAGS_DEBUG) -o $@ $<
|
||||||
|
|
||||||
|
$(PCH_RELEASE): $(INCLUDE_DIR)/pch.h
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CXX_RELEASE) $(PCH_CFLAGS_RELEASE) -o $@ $<
|
||||||
|
|
||||||
|
$(TARGET_DEBUG): $(PCH_DEBUG) $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG)
|
||||||
|
mkdir -p $(BIN_DIR)
|
||||||
|
$(CXX_DEBUG) $(CFLAGS_DEBUG) -o $@ $(OBJ_DEBUG) $(UNICODE_OBJ_DEBUG) $(LIBS)
|
||||||
|
|
||||||
|
$(TARGET_RELEASE): $(PCH_RELEASE) $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE)
|
||||||
|
mkdir -p $(BIN_DIR)
|
||||||
|
$(CXX_RELEASE) $(CFLAGS_RELEASE) -o $@ $(OBJ_RELEASE) $(UNICODE_OBJ_RELEASE) $(LIBS)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/debug/%.o: $(SRC_DIR)/%.cc $(PCH_DEBUG)
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CXX_DEBUG) $(CFLAGS_DEBUG) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/release/%.o: $(SRC_DIR)/%.cc $(PCH_RELEASE)
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CXX_RELEASE) $(CFLAGS_RELEASE) -include $(INCLUDE_DIR)/pch.h -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/debug/unicode_width/%.o: libs/unicode_width/%.c
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CXX_DEBUG) $(CFLAGS_DEBUG) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/release/unicode_width/%.o: libs/unicode_width/%.c
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
$(CXX_RELEASE) $(CFLAGS_RELEASE) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
DEP_DEBUG += $(UNICODE_OBJ_DEBUG:.o=.d)
|
||||||
|
DEP_RELEASE += $(UNICODE_OBJ_RELEASE:.o=.d)
|
||||||
|
|
||||||
|
-include $(DEP_DEBUG)
|
||||||
|
-include $(DEP_RELEASE)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(OBJ_DIR) $(BIN_DIR)
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# ---------------------------------------------
|
# ----------------------------------------------
|
||||||
# Bash Syntax Highlighter Test Specification
|
# Bash Syntax Highlighter Test Specification
|
||||||
# ---------------------------------------------
|
# ----------------------------------------------
|
||||||
|
|
||||||
VERSION="1.0.0"
|
VERSION="1.0.0"
|
||||||
declare -a ITEMS=("alpha" "beta" "gamma" "delta")
|
declare -a ITEMS=("alpha" "beta" "gamma" "delta")
|
||||||
@@ -22,18 +22,20 @@ colorize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Example of error handling
|
# Example of error handling
|
||||||
|
|
||||||
handle_error() {
|
handle_error() {
|
||||||
log ERROR "An error occurred on line $1"
|
log ERROR "An error occurred on line $1"
|
||||||
}
|
}
|
||||||
trap 'handle_error $LINENO' ERR
|
trap 'handle_error $LINENO' ERR
|
||||||
|
|
||||||
# Multiline string test
|
# Multiline string test
|
||||||
read -r -d '' MULTI <<'EOF'
|
read -r -d '' MULTI <<'CPP'
|
||||||
This is a multi-line
|
|
||||||
string used to test
|
int main() {
|
||||||
syntax highlighting for
|
|
||||||
here-documents.
|
}
|
||||||
EOF
|
|
||||||
|
CPP
|
||||||
|
|
||||||
log INFO "Multi-line string loaded"
|
log INFO "Multi-line string loaded"
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@ while ((counter < 5)); do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Subshelled loops and alternating quoting
|
# Subshelled loops and alternating quoting
|
||||||
for item in "${ITEMS[@]}"; do
|
for item in "${ITEMS[@]}}"; do
|
||||||
(
|
(
|
||||||
msg="Processing $item"
|
msg="Processing $item"
|
||||||
echo "$(colorize blue "$msg")"
|
echo "$(colorize blue "$msg")"
|
||||||
@@ -139,3 +141,4 @@ log INFO "You typed: $user_input"
|
|||||||
|
|
||||||
# End marker
|
# End marker
|
||||||
log INFO "Script finished (version $VERSION)"
|
log INFO "Script finished (version $VERSION)"
|
||||||
|
|
||||||
|
|||||||
71
samples/css.css
Normal file
71
samples/css.css
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/* === Basic selectors === */
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: system-ui, sans-serif;
|
||||||
|
background: #121212;
|
||||||
|
color: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Class + ID + attribute */
|
||||||
|
#main.container[data-theme="dark"] {
|
||||||
|
padding: 1rem;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pseudo-classes & elements */
|
||||||
|
a:hover,
|
||||||
|
a:focus-visible {
|
||||||
|
color: hsl(210, 80%, 60%);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
input::placeholder {
|
||||||
|
color: #999;
|
||||||
|
background-color: #523;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CSS variables */
|
||||||
|
:root {
|
||||||
|
--accent: #4fc3f7;
|
||||||
|
--spacing: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
background: var(--accent);
|
||||||
|
padding: calc(var(--spacing) * 1.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Media query */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.container {
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keyframes */
|
||||||
|
@keyframes fade-in {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(10px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animation usage */
|
||||||
|
.modal {
|
||||||
|
animation: fade-in 250ms ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Complex selector */
|
||||||
|
ul > li:not(:last-child)::after {
|
||||||
|
content: "•";
|
||||||
|
margin-left: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Edge cases */
|
||||||
|
[data-value^="test"]::before {
|
||||||
|
content: attr(data-value);
|
||||||
|
}
|
||||||
102
samples/diff.patch
Normal file
102
samples/diff.patch
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
--- ./samples/toml.toml 2025-12-26 19:02:50.480936043 +0000
|
||||||
|
+++ ./samples/yaml.yml 2025-12-26 19:03:27.879765974 +0000
|
||||||
|
@@ -2,52 +2,65 @@
|
||||||
|
# Basic types
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
-title = "Example TOML Configuration"
|
||||||
|
-enabled = true
|
||||||
|
-count = 42
|
||||||
|
-pi = 3.14159
|
||||||
|
-empty = ""
|
||||||
|
+title: "Example YAML Configuration"
|
||||||
|
+enabled: true
|
||||||
|
+count: 42
|
||||||
|
+pi: 3.14159
|
||||||
|
+empty: ""
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
-# Arrays
|
||||||
|
+# Arrays / Lists
|
||||||
|
# ============================================================
|
||||||
|
-fruits = ["apple", "banana", "cherry"]
|
||||||
|
-numbers = [1, 2, 3, 4, 5]
|
||||||
|
+fruits:
|
||||||
|
+ - apple
|
||||||
|
+ - banana
|
||||||
|
+ - cherry
|
||||||
|
|
||||||
|
-# Nested array
|
||||||
|
-matrix = [[1, 2], [3, 4]]
|
||||||
|
+numbers:
|
||||||
|
+ - 1
|
||||||
|
+ - 2
|
||||||
|
+ - 3
|
||||||
|
+ - 4
|
||||||
|
+ - 5
|
||||||
|
+
|
||||||
|
+matrix:
|
||||||
|
+ - [1, 2]
|
||||||
|
+ - [3, 4]
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
-# Tables
|
||||||
|
+# Nested objects / maps
|
||||||
|
# ============================================================
|
||||||
|
-[owner]
|
||||||
|
-name = "Alice"
|
||||||
|
-dob = 1979-05-27T07:32:00Z
|
||||||
|
-
|
||||||
|
-[database]
|
||||||
|
-server = "192.168.1.1"
|
||||||
|
-ports = [ 8001, 8001, 8002 ]
|
||||||
|
-connection_max = 5000
|
||||||
|
-enabled = true
|
||||||
|
+owner:
|
||||||
|
+ name: Alice
|
||||||
|
+ dob: 1979-05-27T07:32:00Z
|
||||||
|
|
||||||
|
-[servers.alpha]
|
||||||
|
-ip = "10.0.0.1"
|
||||||
|
-dc = "east"
|
||||||
|
+database:
|
||||||
|
+ server: 192.168.1.1
|
||||||
|
+ ports:
|
||||||
|
+ - 8001
|
||||||
|
+ - 8001
|
||||||
|
+ - 8002
|
||||||
|
+ connection_max: 5000
|
||||||
|
+ enabled: true
|
||||||
|
|
||||||
|
-[servers.beta]
|
||||||
|
-ip = "10.0.0.2"
|
||||||
|
-dc = "west"
|
||||||
|
+servers:
|
||||||
|
+ alpha:
|
||||||
|
+ ip: 10.0.0.1
|
||||||
|
+ dc: east
|
||||||
|
+ beta:
|
||||||
|
+ ip: 10.0.0.2
|
||||||
|
+ dc: west
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
-# Inline tables
|
||||||
|
+# Multiline string
|
||||||
|
# ============================================================
|
||||||
|
-clients = { name = "Bob", age = 30, active = true }
|
||||||
|
+description: |
|
||||||
|
+ This is a YAML file
|
||||||
|
+ used for testing syntax highlighting.
|
||||||
|
+ It supports multiple lines.
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
-# Multiline strings
|
||||||
|
+# Special characters
|
||||||
|
# ============================================================
|
||||||
|
-description = """
|
||||||
|
-This is a TOML file
|
||||||
|
-used for testing syntax highlighting.
|
||||||
|
-It supports multiple lines.
|
||||||
|
-"""
|
||||||
|
+regex_pattern: "^[A-Za-z0-9_]+$"
|
||||||
|
+path: "C:\\Users\\Alice\\Documents"
|
||||||
71
samples/embedded_template.erb
Normal file
71
samples/embedded_template.erb
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<%# app/views/users/show.html.erb %>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title><%= @user.name %> — Profile</title>
|
||||||
|
|
||||||
|
<%# Inline Ruby expression %>
|
||||||
|
<meta name="description" content="<%= @user.bio %>">
|
||||||
|
|
||||||
|
<% if @dark_mode %>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #111;
|
||||||
|
color: #eee;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<% end %>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- HTML comment -->
|
||||||
|
<header>
|
||||||
|
<h1>Welcome, <%= @user.name %></h1>
|
||||||
|
<p class="subtitle">
|
||||||
|
Member since <%= @user.created_at.strftime("%Y") %>
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<% if @user.admin? %>
|
||||||
|
<section class="admin-panel">
|
||||||
|
<h2>Admin Tools</h2>
|
||||||
|
<ul>
|
||||||
|
<% @tools.each do |tool| %>
|
||||||
|
<li><%= tool.title %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
<% else %>
|
||||||
|
<p>You do not have admin privileges.</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<section class="posts">
|
||||||
|
<% @posts.each do |post| %>
|
||||||
|
<article class="post">
|
||||||
|
<h3><%= post.title %></h3>
|
||||||
|
<p><%= truncate(post.body, length: 140) %></p>
|
||||||
|
|
||||||
|
<%# Conditional rendering %>
|
||||||
|
<% if post.published? %>
|
||||||
|
<span class="status published">Published</span>
|
||||||
|
<% else %>
|
||||||
|
<span class="status draft">Draft</span>
|
||||||
|
<% end %>
|
||||||
|
</article>
|
||||||
|
<% end %>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>© <%= Time.now.year %> Example Corp</p>
|
||||||
|
<%= link_to "Privacy Policy", "/privacy" %>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// JavaScript inside ERB
|
||||||
|
const userName = "<%= j @user.name %>";
|
||||||
|
console.log(`Loaded profile for ${userName}`);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
93
samples/fish.fish
Normal file
93
samples/fish.fish
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
#!/usr/bin/env fish
|
||||||
|
# Fish highlighting torture test
|
||||||
|
|
||||||
|
# === Variables ===
|
||||||
|
set normal_var hello
|
||||||
|
set -l local_var 123
|
||||||
|
set -gx GLOBAL_VAR world
|
||||||
|
set PATH $PATH /usr/local/bin
|
||||||
|
set --erase OLD_VAR
|
||||||
|
|
||||||
|
# Builtin variables
|
||||||
|
echo $HOME $PWD $USER $FISH_VERSION
|
||||||
|
|
||||||
|
# === Strings ===
|
||||||
|
set single 'single quoted string'
|
||||||
|
set double "double quoted $normal_var"
|
||||||
|
set escaped "newline\n tab\t dollar\$"
|
||||||
|
|
||||||
|
# === Conditionals ===
|
||||||
|
if test $normal_var = hello
|
||||||
|
echo equal
|
||||||
|
else if test $normal_var != world
|
||||||
|
echo "not equal"
|
||||||
|
end
|
||||||
|
|
||||||
|
# === Logical operators ===
|
||||||
|
true and echo yes
|
||||||
|
false or echo fallback
|
||||||
|
not false
|
||||||
|
|
||||||
|
# === Arithmetic ===
|
||||||
|
set x 10
|
||||||
|
set y 20
|
||||||
|
math "$x + $y"
|
||||||
|
if test (math "$x * 2") -gt 15
|
||||||
|
echo "math works"
|
||||||
|
end
|
||||||
|
|
||||||
|
# === Loops ===
|
||||||
|
for i in 1 2 3
|
||||||
|
echo "loop $i"
|
||||||
|
end
|
||||||
|
|
||||||
|
while test $x -gt 0
|
||||||
|
set x (math "$x - 1")
|
||||||
|
end
|
||||||
|
|
||||||
|
# === Functions ===
|
||||||
|
function greet --argument name
|
||||||
|
echo "Hello $name"
|
||||||
|
end
|
||||||
|
|
||||||
|
greet world
|
||||||
|
|
||||||
|
# === Command substitution ===
|
||||||
|
set files (ls | grep ".fish")
|
||||||
|
|
||||||
|
# === Redirections ===
|
||||||
|
echo output >/tmp/fish_test.txt
|
||||||
|
cat </tmp/fish_test.txt >>/tmp/fish_log.txt
|
||||||
|
|
||||||
|
# === Process substitution ===
|
||||||
|
diff (ls /bin) (ls /usr/bin)
|
||||||
|
|
||||||
|
# === Case statement ===
|
||||||
|
switch $argv[1]
|
||||||
|
case start
|
||||||
|
echo Starting
|
||||||
|
case stop
|
||||||
|
echo Stopping
|
||||||
|
case '*'
|
||||||
|
echo Unknown
|
||||||
|
end
|
||||||
|
|
||||||
|
# === Subshell ===
|
||||||
|
begin
|
||||||
|
echo "inside begin/end"
|
||||||
|
end
|
||||||
|
|
||||||
|
# === Comments & operators ===
|
||||||
|
# && || | & ! should all highlight
|
||||||
|
true && echo ok || echo fail
|
||||||
|
|
||||||
|
# === Regex ===
|
||||||
|
string match -r '^[a-z]+$' hello
|
||||||
|
|
||||||
|
# === Test builtin ===
|
||||||
|
test -f /etc/passwd
|
||||||
|
test ! -d /does/not/exist
|
||||||
|
|
||||||
|
# === Exit ===
|
||||||
|
exit 0
|
||||||
|
|
||||||
81
samples/gdscript.gd
Normal file
81
samples/gdscript.gd
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
# Sample GDScript for syntax highlighting
|
||||||
|
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Constants
|
||||||
|
# ============================================================
|
||||||
|
const MAX_HEALTH = 100
|
||||||
|
const PLAYER_SPEED = 200
|
||||||
|
const PI_APPROX = 3.14159
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Exported variables
|
||||||
|
# ============================================================
|
||||||
|
@export var player_name: String = "Hero"
|
||||||
|
@export var is_alive: bool = true
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Signals
|
||||||
|
# ============================================================
|
||||||
|
signal health_changed(new_health)
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Member variables
|
||||||
|
# ============================================================
|
||||||
|
var health: int = MAX_HEALTH
|
||||||
|
var velocity: Vector2 = Vector2.ZERO
|
||||||
|
var inventory: Array = []
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Functions
|
||||||
|
# ============================================================
|
||||||
|
func _ready() -> void:
|
||||||
|
print("Player ready:", player_name)
|
||||||
|
_initialize_inventory()
|
||||||
|
set_process(true)
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
if is_alive:
|
||||||
|
_handle_input(delta)
|
||||||
|
_check_health()
|
||||||
|
|
||||||
|
# Private functions
|
||||||
|
func _initialize_inventory() -> void:
|
||||||
|
inventory.append("Sword")
|
||||||
|
inventory.append("Shield")
|
||||||
|
|
||||||
|
func _handle_input(delta: float) -> void:
|
||||||
|
var direction: Vector2 = Vector2.ZERO
|
||||||
|
if Input.is_action_pressed("ui_right"):
|
||||||
|
direction.x += 1
|
||||||
|
if Input.is_action_pressed("ui_left"):
|
||||||
|
direction.x -= 1
|
||||||
|
if Input.is_action_pressed("ui_down"):
|
||||||
|
direction.y += 1
|
||||||
|
if Input.is_action_pressed("ui_up"):
|
||||||
|
direction.y -= 1
|
||||||
|
|
||||||
|
velocity = direction.normalized() * PLAYER_SPEED
|
||||||
|
position += velocity * delta
|
||||||
|
|
||||||
|
func _check_health() -> void:
|
||||||
|
if health <= 0:
|
||||||
|
is_alive = false
|
||||||
|
print("Player is dead!")
|
||||||
|
else:
|
||||||
|
emit_signal("health_changed", health)
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Example of class definition inside another script
|
||||||
|
# ============================================================
|
||||||
|
class Weapon:
|
||||||
|
var name: String
|
||||||
|
var damage: int
|
||||||
|
|
||||||
|
func _init(name: String, damage: int):
|
||||||
|
self.name = name
|
||||||
|
self.damage = damage
|
||||||
|
|
||||||
|
func attack():
|
||||||
|
print(name, "attacks for", damage, "damage")
|
||||||
95
samples/go.go
Normal file
95
samples/go.go
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
// file: go.go
|
||||||
|
package example_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Simple interface
|
||||||
|
type Adder interface {
|
||||||
|
Add(a, b int) int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Concrete implementation
|
||||||
|
type Calculator struct{}
|
||||||
|
|
||||||
|
func (Calculator) Add(a, b int) int {
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic helper
|
||||||
|
func Max[T ~int | ~float64](a, b T) T {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table-driven test
|
||||||
|
func TestAdd(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
a, b int
|
||||||
|
expected int
|
||||||
|
}{
|
||||||
|
{"positive", 2, 3, 5},
|
||||||
|
{"negative", -2, -3, -5},
|
||||||
|
{"mixed", -2, 5, 3},
|
||||||
|
}
|
||||||
|
|
||||||
|
var calc Adder = Calculator{}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := calc.Add(tt.a, tt.b); got != tt.expected {
|
||||||
|
t.Fatalf("Add(%d, %d) = %d; want %d",
|
||||||
|
tt.a, tt.b, got, tt.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Concurrency + context test
|
||||||
|
func TestWorker(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ch := make(chan int)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
select {
|
||||||
|
case ch <- 42:
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case v := <-ch:
|
||||||
|
if v != 42 {
|
||||||
|
t.Errorf("unexpected value: %d", v)
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Fatal("timed out")
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw string + math edge case
|
||||||
|
func TestRawString(t *testing.T) {
|
||||||
|
raw := `line 1
|
||||||
|
line 2
|
||||||
|
\t not escaped
|
||||||
|
`
|
||||||
|
if len(raw) == 0 || math.IsNaN(float64(len(raw))) {
|
||||||
|
t.Fatal("impossible condition reached")
|
||||||
|
}
|
||||||
|
}
|
||||||
32
samples/go.mod
Normal file
32
samples/go.mod
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
module github.com/example/project
|
||||||
|
|
||||||
|
go 1.21
|
||||||
|
|
||||||
|
// ==============================
|
||||||
|
// Direct dependencies
|
||||||
|
// ==============================
|
||||||
|
require (
|
||||||
|
github.com/sirupsen/logrus v1.10.0
|
||||||
|
golang.org/x/net v0.10.0
|
||||||
|
github.com/pkg/errors v0.9.2 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==============================
|
||||||
|
// Replace dependencies
|
||||||
|
// ==============================
|
||||||
|
replace (
|
||||||
|
github.com/old/dependency v1.2.3 => github.com/new/dependency v1.2.4
|
||||||
|
golang.org/x/oldnet => golang.org/x/net v0.11.0
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==============================
|
||||||
|
// Exclude dependencies
|
||||||
|
// ==============================
|
||||||
|
exclude github.com/bad/dependency v1.0.0
|
||||||
|
|
||||||
|
// ==============================
|
||||||
|
// Indirect dependencies
|
||||||
|
// ==============================
|
||||||
|
require (
|
||||||
|
github.com/another/pkg v1.3.0 // indirect
|
||||||
|
)
|
||||||
59
samples/haskell.hs
Normal file
59
samples/haskell.hs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
-- File: haskell.hs
|
||||||
|
{-# LANGUAGE GADTs, TypeFamilies #-}
|
||||||
|
|
||||||
|
module SyntaxTest where
|
||||||
|
|
||||||
|
import Data.List (sort)
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
|
-- Simple data type
|
||||||
|
data Person = Person
|
||||||
|
{ name :: String
|
||||||
|
, age :: Int
|
||||||
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
|
-- GADT
|
||||||
|
data Expr a where
|
||||||
|
I :: Int -> Expr Int
|
||||||
|
B :: Bool -> Expr Bool
|
||||||
|
Add :: Expr Int -> Expr Int -> Expr Int
|
||||||
|
Eq :: Expr Int -> Expr Int -> Expr Bool
|
||||||
|
|
||||||
|
-- Type class
|
||||||
|
class Describable a where
|
||||||
|
describe :: a -> String
|
||||||
|
|
||||||
|
instance Describable Person where
|
||||||
|
describe (Person n a) = n ++ " is " ++ show a ++ " years old."
|
||||||
|
|
||||||
|
-- Function with pattern matching
|
||||||
|
sumList :: [Int] -> Int
|
||||||
|
sumList [] = 0
|
||||||
|
sumList (x:xs) = x + sumList xs
|
||||||
|
|
||||||
|
-- Lambda and higher-order functions
|
||||||
|
applyTwice :: (a -> a) -> a -> a
|
||||||
|
applyTwice f x = f (f x)
|
||||||
|
|
||||||
|
-- Infix operator
|
||||||
|
infixl 6 +++
|
||||||
|
(+++) :: Int -> Int -> Int
|
||||||
|
a +++ b = a + b
|
||||||
|
|
||||||
|
-- IO function
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
let people = [Person "Alice" 30, Person "Bob" 25]
|
||||||
|
mapM_ (putStrLn . describe) people
|
||||||
|
print $ sumList [1..10]
|
||||||
|
print $ applyTwice (+1) 5
|
||||||
|
print $ 3 +++ 4
|
||||||
|
print $ Eq (I 2) (Add (I 1) (I 1))
|
||||||
|
|
||||||
|
-- Quasi-quote example
|
||||||
|
someExpr :: Expr Int
|
||||||
|
someExpr = [| Add (I 5) (I 7) |]
|
||||||
|
|
||||||
|
-- Comments and Haddocks
|
||||||
|
-- | This is a Haddock comment
|
||||||
|
-- explaining the module and functions
|
||||||
87
samples/html.html
Normal file
87
samples/html.html
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Injection Test</title>
|
||||||
|
|
||||||
|
<!-- Comment -->
|
||||||
|
<!-- Another comment with spellcheck -->
|
||||||
|
|
||||||
|
<!-- CSS block -->
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
.highlight {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- CSS block with type attribute -->
|
||||||
|
<style type="text/css">
|
||||||
|
p {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- Script block -->
|
||||||
|
<script>
|
||||||
|
console.log("Hello, world!");
|
||||||
|
function greet(name) {
|
||||||
|
alert(`Hello, ${name}`);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Script with type="module" -->
|
||||||
|
<script type="module">
|
||||||
|
import { something } from "./module.js";
|
||||||
|
something();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Script with type="importmap" -->
|
||||||
|
<script type="importmap">
|
||||||
|
{
|
||||||
|
"imports": {
|
||||||
|
"lodash": "/node_modules/lodash-es/lodash\n.js",
|
||||||
|
"key": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Script with type attribute custom -->
|
||||||
|
<script type="text/javascript">
|
||||||
|
console.log("Custom type");
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Main Heading</h1>
|
||||||
|
<h2>Subheading H2</h2>
|
||||||
|
|
||||||
|
<p style="color: red; font-weight: bold">
|
||||||
|
This paragraph has an inline style
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This is <strong>strong text</strong>, <b>bold also</b>,
|
||||||
|
<em>italic text</em>, <i>emphasized</i>, <u>underlined</u>,
|
||||||
|
<s>strikethrough</s>, <del>deleted text</del>, <code>inline code</code>,
|
||||||
|
<kbd>keyboard input</kbd>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a href="https://hello.world"></a>
|
||||||
|
|
||||||
|
<!-- Lit-html / template interpolation -->
|
||||||
|
<button @click="${e => console.log(e)}">Click me</button>
|
||||||
|
<button @click="${e => console.log(e)}">Click me too</button>
|
||||||
|
|
||||||
|
<!-- Input pattern (regex) -->
|
||||||
|
<input type="text" pattern="[0-9]{3}" placeholder="Enter 3 digits" />
|
||||||
|
|
||||||
|
<!-- Event handlers -->
|
||||||
|
<button onclick="alert('Clicked!')">Event Handler</button>
|
||||||
|
<input onchange="console.log(this.value)" />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
41
samples/ini.ini
Normal file
41
samples/ini.ini
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
; =====================================================
|
||||||
|
; Sample INI Configuration
|
||||||
|
; =====================================================
|
||||||
|
|
||||||
|
[general]
|
||||||
|
app_name = MyApp
|
||||||
|
version = 1.2.3
|
||||||
|
debug = true
|
||||||
|
max_users = 100
|
||||||
|
|
||||||
|
[database]
|
||||||
|
host = localhost
|
||||||
|
port = 5432
|
||||||
|
user = admin
|
||||||
|
password = secret
|
||||||
|
timeout = 30
|
||||||
|
|
||||||
|
[paths]
|
||||||
|
log_dir = /var/log/myapp
|
||||||
|
data_dir = ./data
|
||||||
|
cache_dir = ./cache
|
||||||
|
|
||||||
|
[features]
|
||||||
|
enable_feature_x = true
|
||||||
|
enable_feature_y = false
|
||||||
|
feature_list = item1, item2, item3
|
||||||
|
|
||||||
|
[servers]
|
||||||
|
server1 = 192.168.1.10
|
||||||
|
server2 = 192.168.1.11
|
||||||
|
server3 = 192.168.1.12
|
||||||
|
|
||||||
|
; Nested sections (some parsers support this)
|
||||||
|
[servers.backup]
|
||||||
|
server1 = 192.168.2.10
|
||||||
|
server2 = 192.168.2.11
|
||||||
|
|
||||||
|
; Comments and special characters
|
||||||
|
; This is a comment line
|
||||||
|
; Values can also contain special characters like !@#$%^&*()
|
||||||
|
special_value = !@#$%^&*()_+|~=
|
||||||
147
samples/javascript.js
Normal file
147
samples/javascript.js
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
/* ===============================
|
||||||
|
* JavaScript Syntax Torture Test
|
||||||
|
* =============================== */
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// === Imports ===
|
||||||
|
import fs, { readFileSync as rfs } from "fs";
|
||||||
|
import * as path from "path";
|
||||||
|
import defaultExport, { named as alias } from "./module.js";
|
||||||
|
|
||||||
|
// === Constants ===
|
||||||
|
const PI = 3.141592653589793;
|
||||||
|
const HEX = 0xff;
|
||||||
|
const BIN = 0b101010;
|
||||||
|
const OCT = 0o755;
|
||||||
|
const BIG = 123_456_789n;
|
||||||
|
|
||||||
|
// === Variables ===
|
||||||
|
let x = null;
|
||||||
|
var y = undefined;
|
||||||
|
let z = NaN;
|
||||||
|
|
||||||
|
// === Strings ===
|
||||||
|
const s1 = "double quotes";
|
||||||
|
const s2 = 'single quotes';
|
||||||
|
const s3 = `template literal ${1 + 2}`;
|
||||||
|
const s4 = `multi
|
||||||
|
line
|
||||||
|
template`;
|
||||||
|
const s5 = String.raw`raw \n string`;
|
||||||
|
|
||||||
|
// === Escapes ===
|
||||||
|
const esc = "\n\t\r\b\f\\\"\'\u00A9\x41";
|
||||||
|
|
||||||
|
// === Arrays & Objects ===
|
||||||
|
const arr = [1, , 3, ...[4, 5], { a: 1, b: { c: 2 } }];
|
||||||
|
const obj = {
|
||||||
|
key: "value",
|
||||||
|
"weird-key": 123,
|
||||||
|
['dyn' + 'amic']: true,
|
||||||
|
method() {},
|
||||||
|
async asyncMethod() {},
|
||||||
|
*generator() { yield 1; },
|
||||||
|
};
|
||||||
|
|
||||||
|
// === Destructuring ===
|
||||||
|
const { a, b: renamed, ...rest } = obj;
|
||||||
|
const [x1, , x3 = 42] = arr;
|
||||||
|
|
||||||
|
// === Functions ===
|
||||||
|
function normal(a, b = 1, ...rest) {
|
||||||
|
return a + b + rest.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
const arrow = (x = 0) => x * x;
|
||||||
|
const asyncArrow = async () => await Promise.resolve(42);
|
||||||
|
|
||||||
|
// === Classes ===
|
||||||
|
class Example extends Array {
|
||||||
|
static staticField = 123;
|
||||||
|
#privateField = "secret";
|
||||||
|
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
get value() {
|
||||||
|
return this.#privateField;
|
||||||
|
}
|
||||||
|
|
||||||
|
set value(v) {
|
||||||
|
this.#privateField = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Control Flow ===
|
||||||
|
if (true && !false || null ?? true) {
|
||||||
|
console.log("truthy");
|
||||||
|
} else if (false) {
|
||||||
|
console.warn("nope");
|
||||||
|
} else {
|
||||||
|
console.error("never");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const k in obj) {}
|
||||||
|
for (const v of arr) {}
|
||||||
|
|
||||||
|
while (false) {}
|
||||||
|
do {} while (false);
|
||||||
|
|
||||||
|
switch (Math.random()) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Try / Catch ===
|
||||||
|
try {
|
||||||
|
throw new Error("boom");
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e?.message ?? "unknown");
|
||||||
|
} finally {
|
||||||
|
// cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Regex ===
|
||||||
|
const regex1 = /foo|bar/i;
|
||||||
|
const regex2 = /^<script\b(?![^>]*\btype\s*=\s*"(?!module|text\/javascript)[^"]*")[^>]*>$/;
|
||||||
|
|
||||||
|
// === Tagged template ===
|
||||||
|
function tag(strings, ...values) {
|
||||||
|
return strings.raw.join("|") + values.join(",");
|
||||||
|
}
|
||||||
|
tag`hello ${42} world`;
|
||||||
|
|
||||||
|
// === Optional chaining / nullish ===
|
||||||
|
const deep = obj?.a?.b ?? "fallback";
|
||||||
|
|
||||||
|
// === Bitwise ===
|
||||||
|
const mask = (1 << 4) | (1 << 8);
|
||||||
|
|
||||||
|
// === JSON ===
|
||||||
|
const json = JSON.stringify({ a: 1, b: [true, false] }, null, 2);
|
||||||
|
|
||||||
|
// === Top-level await (if supported) ===
|
||||||
|
await Promise.resolve("done");
|
||||||
|
|
||||||
|
// === JSX-like (should still highlight interestingly) ===
|
||||||
|
const jsx = (
|
||||||
|
<Component prop="value">
|
||||||
|
<Child />
|
||||||
|
</Component>
|
||||||
|
);
|
||||||
|
|
||||||
|
// === End ===
|
||||||
|
export default {
|
||||||
|
PI,
|
||||||
|
arr,
|
||||||
|
obj,
|
||||||
|
Example,
|
||||||
|
};
|
||||||
51
samples/json.jsonc
Normal file
51
samples/json.jsonc
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/* Example configuration file (JSONC)
|
||||||
|
// Used to test syntax highlighting and comment support
|
||||||
|
mutiline comment
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
// Application metadata
|
||||||
|
"name": "example-app",
|
||||||
|
"version": "1.2.3",
|
||||||
|
"debug": true,
|
||||||
|
|
||||||
|
// Paths and environment
|
||||||
|
"paths": {
|
||||||
|
"root": "/usr/local/example",
|
||||||
|
"cache": "/tmp/example-cache
|
||||||
|
asa
|
||||||
|
multiline string",
|
||||||
|
"logs": null, // optional
|
||||||
|
},
|
||||||
|
|
||||||
|
// Feature flags
|
||||||
|
"features": {
|
||||||
|
"experimental": false,
|
||||||
|
"hotReload": true,
|
||||||
|
"themes": [
|
||||||
|
"dark",
|
||||||
|
"light",
|
||||||
|
// "solarized" // not ready yet
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
// Network configuration
|
||||||
|
"server": {
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"port": 8080,
|
||||||
|
"ssl": {
|
||||||
|
"enabled": false,
|
||||||
|
"cert": "",
|
||||||
|
"key": "",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Mixed value types
|
||||||
|
"timeouts": [100, 250, 500, null],
|
||||||
|
"retryCount": 3,
|
||||||
|
|
||||||
|
// Escapes and strings
|
||||||
|
"banner": "Welcome!\nThis supports \"escaped quotes\" and unicode → ✓",
|
||||||
|
|
||||||
|
// Trailing comma allowed in JSONC
|
||||||
|
}
|
||||||
119
samples/lua.lua
Normal file
119
samples/lua.lua
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#!/usr/bin/env lua
|
||||||
|
-- Lua syntax highlighting test file
|
||||||
|
|
||||||
|
-- Constants
|
||||||
|
PI = 3.14159
|
||||||
|
MAX_COUNT = 100
|
||||||
|
|
||||||
|
-- Variables
|
||||||
|
local counter = 0
|
||||||
|
local name = "Lua"
|
||||||
|
|
||||||
|
-- Built-in variable
|
||||||
|
print(self)
|
||||||
|
|
||||||
|
-- Functions
|
||||||
|
local function greet(user)
|
||||||
|
print("Hello, " .. user)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function add(a, b)
|
||||||
|
return a + b
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Method definitions
|
||||||
|
local obj = {}
|
||||||
|
function obj:sayHi()
|
||||||
|
print("Hi from method!")
|
||||||
|
end
|
||||||
|
|
||||||
|
obj.sayHello = function()
|
||||||
|
print("Hello from field function!")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Arrow-style anonymous function (LuaJIT/CFFI style)
|
||||||
|
local arrow = function(x)
|
||||||
|
return x * 2
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Table constructors
|
||||||
|
local t = {
|
||||||
|
foo = 123,
|
||||||
|
bar = function()
|
||||||
|
return "bar"
|
||||||
|
end,
|
||||||
|
nested = {
|
||||||
|
a = 1,
|
||||||
|
b = 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Loops
|
||||||
|
for i = 1, MAX_COUNT do
|
||||||
|
counter = counter + i
|
||||||
|
end
|
||||||
|
|
||||||
|
while counter > 0 do
|
||||||
|
counter = counter - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
repeat
|
||||||
|
counter = counter + 1
|
||||||
|
until counter == 10
|
||||||
|
|
||||||
|
-- Conditionals
|
||||||
|
if counter > 5 then
|
||||||
|
print("Big number")
|
||||||
|
elseif counter == 5 then
|
||||||
|
print("Exactly five")
|
||||||
|
else
|
||||||
|
print("Small number")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Operators
|
||||||
|
local x, y = 10, 20
|
||||||
|
local z = x + y * 2 - (x / y) ^ 2
|
||||||
|
local ok = x == y or x ~= y and not false
|
||||||
|
|
||||||
|
-- Function calls
|
||||||
|
greet("World")
|
||||||
|
obj:sayHi()
|
||||||
|
obj.sayHello()
|
||||||
|
add(5, 10)
|
||||||
|
|
||||||
|
-- Built-in function calls
|
||||||
|
assert(x > 0)
|
||||||
|
pcall(function()
|
||||||
|
print("safe")
|
||||||
|
end)
|
||||||
|
tonumber("123")
|
||||||
|
|
||||||
|
-- CFFI injection example
|
||||||
|
local ffi = require("ffi")
|
||||||
|
ffi.cdef([[
|
||||||
|
int printf(const char *fmt, ...);
|
||||||
|
typedef struct { int x; int y; } point;
|
||||||
|
]])
|
||||||
|
|
||||||
|
-- Boolean and nil
|
||||||
|
local flag = true
|
||||||
|
local nothing = nil
|
||||||
|
|
||||||
|
-- Comments
|
||||||
|
-- Single line
|
||||||
|
--[[
|
||||||
|
Multi-line
|
||||||
|
comment
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- Strings
|
||||||
|
local s1 = "Hello\nWorld"
|
||||||
|
local s2 = [[Long
|
||||||
|
multi-line
|
||||||
|
string]]
|
||||||
|
|
||||||
|
-- Template strings (LuaJIT-style)
|
||||||
|
local tpl = `Value: ${counter}`
|
||||||
|
|
||||||
|
-- Regex-like string (for testing injection highlighting)
|
||||||
|
local re = "/^%a+$/"
|
||||||
45
samples/markdown.md
Normal file
45
samples/markdown.md
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# Heading 1
|
||||||
|
|
||||||
|
ones
|
||||||
|
content
|
||||||
|
|
||||||
|
# Heading 2
|
||||||
|
|
||||||
|
### Heading 3
|
||||||
|
|
||||||
|
This is a paragraph with **bold text**, *italic text*, ~~strikethrough~~, and `inline code`.
|
||||||
|
|
||||||
|
> This is a blockquote.
|
||||||
|
>
|
||||||
|
> - Nested list item 1
|
||||||
|
> - Nested list item 2
|
||||||
|
> - Sub-item
|
||||||
|
|
||||||
|
- Task list:
|
||||||
|
- [ ] Unchecked task
|
||||||
|
- [x] Checked task
|
||||||
|
|
||||||
|
1. Numbered list item
|
||||||
|
2. Another item
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
| Name | Age | City |
|
||||||
|
|------------|-----|---------------|
|
||||||
|
| Alice | 25 | London |
|
||||||
|
| Bob | 30 | New York |
|
||||||
|
| Charlie | 22 | San Francisco |
|
||||||
|
|
||||||
|
[Link to OpenAI](https://openai.com)
|
||||||
|
|
||||||
|
`Inline code` example and a fenced code block:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local s2 = [[Long
|
||||||
|
multi-line
|
||||||
|
string]]
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> "This is a quote with a link to [Top](#Heading%202)."
|
||||||
87
samples/nginx.conf
Normal file
87
samples/nginx.conf
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# ============================================================
|
||||||
|
# Global Settings
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
user www-data;
|
||||||
|
worker_processes auto;
|
||||||
|
pid /run/nginx.pid;
|
||||||
|
include /etc/nginx/modules-enabled/*.conf;
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Events Block
|
||||||
|
# ============================================================
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
use epoll;
|
||||||
|
multi_accept on;
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# HTTP Block
|
||||||
|
# ============================================================
|
||||||
|
http {
|
||||||
|
sendfile on;
|
||||||
|
tcp_nopush on;
|
||||||
|
tcp_nodelay on;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
types_hash_max_size 2048;
|
||||||
|
|
||||||
|
include /etc/nginx/mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
access_log /var/log/nginx/access.log;
|
||||||
|
error_log /var/log/nginx/error.log warn;
|
||||||
|
|
||||||
|
# Gzip Settings
|
||||||
|
gzip on;
|
||||||
|
gzip_disable "msie6";
|
||||||
|
|
||||||
|
# ========================================================
|
||||||
|
# Upstream Backend Servers
|
||||||
|
# ========================================================
|
||||||
|
upstream backend {
|
||||||
|
server 127.0.0.1:8080 weight=5;
|
||||||
|
server 127.0.0.1:8081;
|
||||||
|
keepalive 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
# ========================================================
|
||||||
|
# Server Block
|
||||||
|
# ========================================================
|
||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
|
||||||
|
server_name example.com www.example.com;
|
||||||
|
|
||||||
|
root /var/www/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
|
||||||
|
# ====================================================
|
||||||
|
# Location Blocks
|
||||||
|
# ====================================================
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://backend;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~* \.(gif|jpg|jpeg|png|css|js|ico|svg)$ {
|
||||||
|
expires 30d;
|
||||||
|
add_header Cache-Control "public, no-transform";
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 404 /404.html;
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
|
||||||
|
location = /50x.html {
|
||||||
|
root /var/www/html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
136
samples/php.php
Normal file
136
samples/php.php
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>PHP Syntax Stress Test</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* CSS section */
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background: #1e1e1e;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box {
|
||||||
|
border: 1px solid #444;
|
||||||
|
padding: 10px;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// JS section
|
||||||
|
function greet(name) {
|
||||||
|
console.log("Hello " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
greet("World");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Basic variables
|
||||||
|
$number = 42;
|
||||||
|
$text = "Hello PHP";
|
||||||
|
$truth = true;
|
||||||
|
$nothing = null;
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
define("APP_NAME", "SyntaxTester");
|
||||||
|
|
||||||
|
// Arrays
|
||||||
|
$list = [1, 2, 3];
|
||||||
|
$assoc = [
|
||||||
|
"one" => 1,
|
||||||
|
"two" => 2
|
||||||
|
];
|
||||||
|
|
||||||
|
// Function
|
||||||
|
function add(int $a, int $b): int
|
||||||
|
{
|
||||||
|
return $a + $b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Class + methods
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
private string $name;
|
||||||
|
public static int $count = 0;
|
||||||
|
|
||||||
|
public function __construct(string $name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
self::$count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function greet(): string
|
||||||
|
{
|
||||||
|
return "Hello {$this->name}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Object usage
|
||||||
|
$user = new User("Alice");
|
||||||
|
echo $user->greet();
|
||||||
|
|
||||||
|
// Control flow
|
||||||
|
if ($number > 10) {
|
||||||
|
echo "Big number";
|
||||||
|
} elseif ($number === 10) {
|
||||||
|
echo "Exactly ten";
|
||||||
|
} else {
|
||||||
|
echo "Small number";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop
|
||||||
|
foreach ($list as $item) {
|
||||||
|
echo $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Match expression
|
||||||
|
$result = match ($number) {
|
||||||
|
1 => "one",
|
||||||
|
2 => "two",
|
||||||
|
default => "many"
|
||||||
|
};
|
||||||
|
|
||||||
|
// Try / catch
|
||||||
|
try {
|
||||||
|
throw new Exception("Test exception");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Anonymous function
|
||||||
|
$double = fn($x) => $x * 2;
|
||||||
|
|
||||||
|
// Nullsafe operator
|
||||||
|
$len = $user?->name ? strlen($user->name) : 0;
|
||||||
|
|
||||||
|
// Ternary
|
||||||
|
$status = $truth ? "yes" : "no";
|
||||||
|
|
||||||
|
// Include / require
|
||||||
|
require_once "config.php";
|
||||||
|
|
||||||
|
// Output
|
||||||
|
echo "<div class='box'>";
|
||||||
|
echo htmlspecialchars($text);
|
||||||
|
echo "</div>";
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// JS interacting with PHP output
|
||||||
|
const phpValue = <?= json_encode($number) ?>;
|
||||||
|
console.log("Value from PHP:", phpValue);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
163
samples/python.py
Normal file
163
samples/python.py
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Test file for Python Tree-sitter highlighting."""
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Constants / Builtins
|
||||||
|
# ==============================
|
||||||
|
PI = 3.14159
|
||||||
|
MAX_SIZE = 100
|
||||||
|
NotImplemented
|
||||||
|
Ellipsis
|
||||||
|
__name__ # builtin constant
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Imports
|
||||||
|
# ==============================
|
||||||
|
import os
|
||||||
|
import sys as system
|
||||||
|
from re import compile as re_compile
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Functions
|
||||||
|
# ==============================
|
||||||
|
def add(a: int, b: int = 5) -> int:
|
||||||
|
"""Simple add function"""
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
def variadic(*args, **kwargs):
|
||||||
|
print(args, kwargs)
|
||||||
|
|
||||||
|
lambda_func = lambda x, y=2: x * y
|
||||||
|
|
||||||
|
def type_var_example(T: type):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Classes
|
||||||
|
# ==============================
|
||||||
|
class Base:
|
||||||
|
class_var = 10
|
||||||
|
|
||||||
|
def __init__(self, name: str):
|
||||||
|
self.name = name
|
||||||
|
self._private = 42
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def cls_method(cls):
|
||||||
|
return cls.class_var
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def static_method():
|
||||||
|
return "static"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def prop(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
class Derived(Base):
|
||||||
|
def __init__(self, name, extra):
|
||||||
|
super().__init__(name)
|
||||||
|
self.extra = extra
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Variables
|
||||||
|
# ==============================
|
||||||
|
normal_var = 1
|
||||||
|
_local_var = 2
|
||||||
|
GLOBAL_VAR = 3
|
||||||
|
|
||||||
|
# Builtin variable references
|
||||||
|
self = "something"
|
||||||
|
cls = "dj"
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Control flow
|
||||||
|
# ==============================
|
||||||
|
if True:
|
||||||
|
x = 10
|
||||||
|
elif False:
|
||||||
|
x = 20
|
||||||
|
else:
|
||||||
|
x = 0
|
||||||
|
|
||||||
|
for i in range(3):
|
||||||
|
print(i)
|
||||||
|
while x > 0:
|
||||||
|
x -= 1
|
||||||
|
if x == 1:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
1 / 0
|
||||||
|
except ZeroDivisionError as err:
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Operators
|
||||||
|
# ==============================
|
||||||
|
a, b = 5, 10
|
||||||
|
c = a + b * 2 // 3 % 4 ** 2
|
||||||
|
d = (a << 2) & b | c ^ ~a
|
||||||
|
ef = not a or b and c
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# f-strings / interpolation
|
||||||
|
# ==============================
|
||||||
|
name = "Alice"
|
||||||
|
greeting = f"Hello {name.upper()}!"
|
||||||
|
formatted = f"{a + b} is sum"
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Regex
|
||||||
|
# ==============================
|
||||||
|
pattern1 = re_compile(r"\d+")
|
||||||
|
pattern2 = re_compile(r"\w{2,}")
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Decorators usage
|
||||||
|
# ==============================
|
||||||
|
@staticmethod
|
||||||
|
def static_func():
|
||||||
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def cls_func(cls):
|
||||||
|
return cls
|
||||||
|
|
||||||
|
# @custom_decorator
|
||||||
|
def decorated_func():
|
||||||
|
return None
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Misc / Type conversions / literals
|
||||||
|
# ==============================
|
||||||
|
flag: bool = True
|
||||||
|
nothing: None = None
|
||||||
|
num: float = float("3.14")
|
||||||
|
text: str = str(123)
|
||||||
|
lst = [1, 2, 3]
|
||||||
|
tpl = (4, 5)
|
||||||
|
dct = {"a": 1, "b": 2}
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Type hints / TypeVar / TypeAlias
|
||||||
|
# ==============================
|
||||||
|
from typing import TypeVar, NewType
|
||||||
|
T = TypeVar("T")
|
||||||
|
UserId = NewType("UserId", int)
|
||||||
|
TypeAliasExample: type = int
|
||||||
|
|
||||||
|
# ==============================
|
||||||
|
# Function calls / constructors
|
||||||
|
# ==============================
|
||||||
|
result = add(1, 2)
|
||||||
|
obj = Derived("Alice", "extra")
|
||||||
|
variadic(1, 2, 3, key="value")
|
||||||
|
instance_check = isinstance(obj, Base)
|
||||||
18
samples/regex.regex
Normal file
18
samples/regex.regex
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Match email addresses with optional names
|
||||||
|
(?P<name>[a-zA-Z0-9._%+-]+)?\s*<(?P<email>[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})>
|
||||||
|
|
||||||
|
# Match dates in YYYY-MM-DD or DD/MM/YYYY
|
||||||
|
(\d{4}-\d{2}-\d{2})|(\d{2}/\d{2}/\d{4})
|
||||||
|
|
||||||
|
# Match hexadecimal colors
|
||||||
|
# e.g., #FFF, #FFFFFF
|
||||||
|
# Optional leading #
|
||||||
|
# Case-insensitive
|
||||||
|
# Flags inline
|
||||||
|
(?i)#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})
|
||||||
|
|
||||||
|
# Match words starting with vowels
|
||||||
|
\b[aeiouAEIOU]\w*\b
|
||||||
|
|
||||||
|
# Match simple URL
|
||||||
|
https?://(?:www\.)?\w+\.\w+(?:/\S*)?
|
||||||
193
samples/ruby.rb
193
samples/ruby.rb
@@ -1,27 +1,158 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
# Unicode / Emoji / CJK stress-test Ruby file
|
||||||
|
# Purpose: Test syntax highlighting + width calculation in your editor
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
|
||||||
|
# Mixed-width CJKssssssssssssssss LoadErssssssssssssssssssssssss
|
||||||
|
cjk_samples = [
|
||||||
|
'漢字テスト',
|
||||||
|
'測試中文字串',
|
||||||
|
'한국어 테스트',
|
||||||
|
'ひらがなカタカナ混合'
|
||||||
|
]
|
||||||
|
|
||||||
|
# a hex color: #FFFFFF shouldn't hl here: hsl(147rad, 50%, 47%) as it is not css-style file
|
||||||
|
|
||||||
|
0x603010 # another hex color
|
||||||
|
|
||||||
|
# Ruby regex with unicode
|
||||||
|
$unicode_regex_multiline = /[一-龯ぁ-ん12288ァ
|
||||||
|
\-ヶー
|
||||||
|
s wow
|
||||||
|
|
||||||
|
々〆〤]/
|
||||||
|
|
||||||
|
UNICORE = /
|
||||||
|
s
|
||||||
|
{#{ss}}
|
||||||
|
\C-s\u{10}
|
||||||
|
/
|
||||||
|
|
||||||
|
UNINITCORE = %(
|
||||||
|
|
||||||
|
{{#{}}}
|
||||||
|
|
||||||
|
test = "A:\x41 B:\101 C:\u0043 D:\u{44 45} NUL:\0 DEL:\c? CTRL_A:\cA META_X:\M-x CTRL_META_X:\C-\M-x MIX:\C-\M-z N:\N{UNICODE NAME}"
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
# Unicode identifiers (valid in Ruby)
|
||||||
|
变量 = 0x5_4eddaee
|
||||||
|
π = 0.314_159e+2, ?\u0234, "\,", ?\x0A, 's', true, false, 0
|
||||||
|
挨拶 = -> { "こんに \n ちは" }
|
||||||
|
|
||||||
|
arr = []
|
||||||
|
not_arr = NotABuiltin.new
|
||||||
|
|
||||||
|
raise NameError or SystemExit or CustomError or Errno or ErrorNotAtAll
|
||||||
|
|
||||||
|
# Method using unicode variable names
|
||||||
|
def math_test
|
||||||
|
puts "π * 2 = #{π * 2}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Iterate through CJK samples
|
||||||
|
cjk_samples.each_with_index do |str, idx:|
|
||||||
|
puts %! CJK[#{idx}] => #{str} (len=#{str.length})\! !
|
||||||
|
symbol = :"
|
||||||
|
a
|
||||||
|
"
|
||||||
|
sym2 = :hello
|
||||||
|
end
|
||||||
|
|
||||||
|
# Test emoji width behaviors
|
||||||
|
puts "Emoji count: #{emojis.length}"
|
||||||
|
|
||||||
|
# Multi-line string with unicode
|
||||||
|
multi = <<~BASH
|
||||||
|
# Function recursion demo
|
||||||
|
factorial() {
|
||||||
|
local n="$1"
|
||||||
|
if ((n <= 1)); then
|
||||||
|
echo 1
|
||||||
|
else\ns
|
||||||
|
local prev
|
||||||
|
prev=$(factorial $((n - 1)))
|
||||||
|
echo $((n * prev))
|
||||||
|
before #{ interpol
|
||||||
|
# {' '}
|
||||||
|
# comment should be fine heres s
|
||||||
|
$a / $-s + 0xFF
|
||||||
|
}s#{' '}
|
||||||
|
x
|
||||||
|
a after
|
||||||
|
fi
|
||||||
|
} #{s}
|
||||||
|
log INFO "factorial(5) = $(factorial 5)"
|
||||||
|
BASH
|
||||||
|
|
||||||
|
puts multi
|
||||||
|
|
||||||
|
|
||||||
|
# Arrays mixing everything
|
||||||
|
mixed = [
|
||||||
|
'🐍 Ruby + Python? sacrilege! 🐍',
|
||||||
|
'日本語とEnglishと🔧mix',
|
||||||
|
'Spacing test →→→→→→→',
|
||||||
|
'Zero-width joiner test: 👨👩👧👦 family emoji'
|
||||||
|
]
|
||||||
|
|
||||||
|
two_docs = <<~DOC1, <<~DOC2
|
||||||
|
stuff for doc2
|
||||||
|
rdvajehvbaejbfh
|
||||||
|
DOC1
|
||||||
|
stuff for doc 2 with #{!interpolation} and more
|
||||||
|
DOC2
|
||||||
|
|
||||||
|
p = 0 << 22 # not a heredoc
|
||||||
|
|
||||||
|
mixed.each { |m| puts m }
|
||||||
|
|
||||||
|
# Unicode in comments — highlight me!
|
||||||
|
# コメント:エディタのハイライトを確認します✨
|
||||||
|
# Emojis should not break formatting: 🦀🦊🐱👤🤖
|
||||||
|
|
||||||
|
# Dummy Ruby logic
|
||||||
|
5.times do |i|
|
||||||
|
puts "Loop #{i}: 🌟 #{cjk_samples[i % cjk_samples.size]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# String escape sequences + unicode
|
||||||
|
escaped = "Line1\nLine2\tTabbed 😀"
|
||||||
|
puts escaped
|
||||||
|
|
||||||
|
p = 0 << 2
|
||||||
|
# Frozen string literal test
|
||||||
|
# frozen_string_literal: true
|
||||||
|
const_str = '定数文字列🔒'.freeze
|
||||||
|
puts const_str
|
||||||
|
|
||||||
|
# End marker
|
||||||
|
puts '--- END OF UNICODE TEST FILE ---'
|
||||||
|
|
||||||
# Ruby syntax highlighting test
|
# Ruby syntax highlighting test
|
||||||
|
|
||||||
=begin
|
# This is a multi-line comment.
|
||||||
This is a multi-line comment.
|
# It spans multiple lines.
|
||||||
It spans multiple lines.
|
# Good for testing highlighting.
|
||||||
Good for testing highlighting.
|
#
|
||||||
|
# This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped linetest,
|
||||||
This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test, This is a wrapped line test,
|
#
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
|
|
||||||
PI = 3.14159
|
PI = 3.14159
|
||||||
MAX_ITER = 5
|
MAX_ITER = 5
|
||||||
|
|
||||||
# Module
|
# Module
|
||||||
module Utilities
|
module Utilities
|
||||||
def self.random_greeting
|
def self.random_greeting
|
||||||
["Hello", "Hi", "Hey", "Hola", "Bonjour", "Merhaba"].sample
|
%w[Hello Hi Hey Hola Bonjour Merhaba].sample
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.factorial(n)
|
def self.factorial(n)
|
||||||
return 1 if n <= 1
|
return 1 if n <= 1
|
||||||
|
|
||||||
n * factorial(n - 1)
|
n * factorial(n - 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -39,6 +170,8 @@ class TestObject
|
|||||||
puts "#{@name}: #{@value}"
|
puts "#{@name}: #{@value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def double_value
|
def double_value
|
||||||
@value * 2
|
@value * 2
|
||||||
end
|
end
|
||||||
@@ -80,11 +213,16 @@ end
|
|||||||
# Method definition
|
# Method definition
|
||||||
def greet_person(name)
|
def greet_person(name)
|
||||||
puts "#{Utilities.random_greeting}, #{name}!"
|
puts "#{Utilities.random_greeting}, #{name}!"
|
||||||
|
return true if name == 'harry'
|
||||||
|
|
||||||
|
's'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
h = a / a
|
||||||
|
|
||||||
# Calling methods
|
# Calling methods
|
||||||
greet_person("Alice")
|
greet_person('Alice')
|
||||||
greet_person("Bob")
|
greet_person('Bob')
|
||||||
|
|
||||||
# Loops
|
# Loops
|
||||||
i = 0
|
i = 0
|
||||||
@@ -104,7 +242,7 @@ begin
|
|||||||
rescue ZeroDivisionError => e
|
rescue ZeroDivisionError => e
|
||||||
puts "Caught an error: #{e}"
|
puts "Caught an error: #{e}"
|
||||||
ensure
|
ensure
|
||||||
puts "This runs no matter what"
|
puts 'This runs no matter what'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Arrays of objects
|
# Arrays of objects
|
||||||
@@ -140,7 +278,7 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Special objects
|
# Special objects
|
||||||
so = SpecialObject.new("Special", 10)
|
so = SpecialObject.new('Special', 10)
|
||||||
puts "Double: #{so.double_value}, Triple: #{so.triple_value}"
|
puts "Double: #{so.double_value}, Triple: #{so.triple_value}"
|
||||||
|
|
||||||
# String interpolation and formatting
|
# String interpolation and formatting
|
||||||
@@ -148,16 +286,19 @@ puts "PI is approximately #{PI.round(2)}"
|
|||||||
|
|
||||||
# Multi-line strings
|
# Multi-line strings
|
||||||
multi_line = <<~TEXT
|
multi_line = <<~TEXT
|
||||||
|
k kmW ;
|
||||||
This is a multi-line string.
|
This is a multi-line string.
|
||||||
It spans multiple lines.
|
It spans multiple lines.
|
||||||
Good for testing highlighting.
|
Gossn sssmss
|
||||||
|
ddsss
|
||||||
|
od for testing highlighting.
|
||||||
TEXT
|
TEXT
|
||||||
|
|
||||||
puts multi_line
|
puts multi_line
|
||||||
|
|
||||||
# Symbols and strings
|
# Symbols and strings
|
||||||
sym = :my_symbol
|
sym = :my_symbol == __dir__
|
||||||
str = "my string"
|
str = 'my string'
|
||||||
puts "Symbol: #{sym}, String: #{str}"
|
puts "Symbol: #{sym}, String: #{str}"
|
||||||
|
|
||||||
# Random numbers
|
# Random numbers
|
||||||
@@ -176,20 +317,28 @@ end
|
|||||||
|
|
||||||
# Block with yield
|
# Block with yield
|
||||||
def wrapper
|
def wrapper
|
||||||
puts "Before block"
|
puts 'Before block'
|
||||||
yield if block_given?
|
yield if block_given?
|
||||||
puts "After block"
|
puts 'After block'
|
||||||
end
|
end
|
||||||
|
|
||||||
wrapper { puts "Inside block" }
|
# ss
|
||||||
|
|
||||||
|
wrapper { puts 'Inside block' }
|
||||||
|
|
||||||
# Sorting
|
# Sorting
|
||||||
sorted = rand_nums.sort
|
sorted = rand_nums.sort
|
||||||
puts "Sorted: #{sorted.join(', ')}"
|
puts "Sorted: #{sorted.join(', ')}"
|
||||||
|
|
||||||
# Regex
|
# Regex
|
||||||
sample_text = "The quick brown fox jumps over the lazy dog"
|
sample_text = 'The quick brown fox jumps over the lazy dog'
|
||||||
puts "Match 'fox'?" if sample_text =~ /fox/
|
puts "Match 'fox'?" if sample_text =~ /fox/
|
||||||
|
|
||||||
# End of test script
|
# End of test script
|
||||||
puts "Ruby syntax highlighting test complete."
|
puts 'Ruby syntax highlighting test complete.'
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
|
||||||
|
Anything here should be ignored >><<
|
||||||
|
{{{}}}[[[]]](((000)))
|
||||||
|
|||||||
406
samples/rust.rs
Normal file
406
samples/rust.rs
Normal file
@@ -0,0 +1,406 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
use std::collections::{BTreeMap, HashMap};
|
||||||
|
use std::fmt;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
//! Examples to exercise the Rust regex injection queries in the highlights.scm.
|
||||||
|
//! These cover Regex::new, regex::Regex::new, regex::bytes::Regex::new,
|
||||||
|
//! RegexSet::new, regex::RegexSet::new, RegexSetBuilder::new, and byte variants.
|
||||||
|
//!
|
||||||
|
//! Injection patterns in the query file trigger on:
|
||||||
|
//! - call to (Regex|ByteRegexBuilder)::new with a raw string literal
|
||||||
|
//! - call to (RegexSet|RegexSetBuilder)::new with an array of raw string literals
|
||||||
|
|
||||||
|
use regex::{Regex, RegexSet, RegexSetBuilder};
|
||||||
|
use regex::bytes::Regex as ByteRegex;
|
||||||
|
use regex::bytes::RegexSet as ByteRegexSet;
|
||||||
|
use regex::bytes::RegexSetBuilder as ByteRegexSetBuilder;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// --- Should inject (Regex::new with raw string) ---
|
||||||
|
let _simple = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
|
||||||
|
|
||||||
|
// --- Should inject (fully qualified regex::Regex::new with raw string) ---
|
||||||
|
let _fq = regex::Regex::new(r"(?m)^\w+\s*=\s*.+$").unwrap();
|
||||||
|
|
||||||
|
// --- Should inject (bytes::Regex::new with raw string) ---
|
||||||
|
let _bytes = ByteRegex::new(r"(?-u)\xFF[\x00-\x7F]+").unwrap();
|
||||||
|
|
||||||
|
// --- Should inject (RegexSet::new with array of raw strings) ---
|
||||||
|
let _set = RegexSet::new([
|
||||||
|
r"^INFO:",
|
||||||
|
r"^WARN:",
|
||||||
|
r"^ERROR:",
|
||||||
|
]).unwrap();
|
||||||
|
|
||||||
|
// --- Should inject (regex::RegexSet::new fully qualified) ---
|
||||||
|
let _set_fq = regex::RegexSet::new([
|
||||||
|
r"foo\d+",
|
||||||
|
r"bar\d+",
|
||||||
|
]).unwrap();
|
||||||
|
|
||||||
|
// --- Should inject (RegexSetBuilder::new with array of raw strings) ---
|
||||||
|
let _set_builder = RegexSetBuilder::new([
|
||||||
|
r"\bcat\b",
|
||||||
|
r"\bdog\b",
|
||||||
|
])
|
||||||
|
.case_insensitive(true)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// --- Should inject (bytes set builder) ---
|
||||||
|
let _byte_set_builder = ByteRegexSetBuilder::new([
|
||||||
|
r"(?-u)\x01\x02",
|
||||||
|
r"(?-u)\xFF.+",
|
||||||
|
])
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// --- Should inject (bytes set) ---
|
||||||
|
let _byte_set = ByteRegexSet::new([
|
||||||
|
r"(?-u)\x00+\xFF",
|
||||||
|
r"(?-u)[\x10-\x20]+",
|
||||||
|
]).unwrap();
|
||||||
|
|
||||||
|
// --- NEGATIVE examples (should NOT inject) ---
|
||||||
|
|
||||||
|
// Not raw string literal (plain string): the query expects raw_string_literal.
|
||||||
|
let _no_inject_plain = Regex::new("plain-string-no-raw").unwrap();
|
||||||
|
|
||||||
|
// Function name is not `new`, so should not inject.
|
||||||
|
let _builder = Regex::new(r"\d+").map(|re| re.replace("123", "x"));
|
||||||
|
|
||||||
|
// Different type name, should not inject.
|
||||||
|
let _other = Some(r"not a regex call");
|
||||||
|
|
||||||
|
// Raw string but different function, should not inject.
|
||||||
|
let _format = format!(r"literal: {}", 42);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep a simple test to ensure this compiles and runs.
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn smoke() {
|
||||||
|
let re = Regex::new(r"^\d+$").unwrap();
|
||||||
|
assert!(re.is_match("12345"));
|
||||||
|
let set = RegexSet::new([r"cat", r"dog"]).unwrap();
|
||||||
|
assert!(set.is_match("hotdog"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A simple data type to exercise traits, pattern matching, and methods.
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct Point {
|
||||||
|
pub x: i64,
|
||||||
|
pub y: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Point {
|
||||||
|
pub fn manhattan(&self) -> i64 {
|
||||||
|
self.x.abs() + self.y.abs()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn translate(&self, dx: i64, dy: i64) -> Self {
|
||||||
|
Self {
|
||||||
|
x: self.x + dx,
|
||||||
|
y: self.y + dy,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Point {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "({}, {})", self.x, self.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub enum ParseError {
|
||||||
|
Empty,
|
||||||
|
InvalidDigit,
|
||||||
|
TooLarge,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_u8(input: &str) -> Result<u8, ParseError> {
|
||||||
|
if input.trim().is_empty() {
|
||||||
|
return Err(ParseError::Empty);
|
||||||
|
}
|
||||||
|
let mut value: u16 = 0;
|
||||||
|
for ch in input.bytes() {
|
||||||
|
if !(b'0'..=b'9').contains(&ch) {
|
||||||
|
return Err(ParseError::InvalidDigit);
|
||||||
|
}
|
||||||
|
value = value * 10 + u16::from(ch - b'0');
|
||||||
|
if value > u8::MAX as u16 {
|
||||||
|
return Err(ParseError::TooLarge);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(value as u8)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sum_iter<I: IntoIterator<Item = i64>>(iter: I) -> i64 {
|
||||||
|
iter.into_iter().fold(0, |acc, n| acc + n)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn split_once<'a>(input: &'a str, needle: char) -> Option<(&'a str, &'a str)> {
|
||||||
|
let idx = input.find(needle)?;
|
||||||
|
Some((&input[..idx], &input[idx + needle.len_utf8()..]))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn join_with<I: IntoIterator<Item = String>>(iter: I, sep: &str) -> String {
|
||||||
|
let mut it = iter.into_iter().peekable();
|
||||||
|
let mut out = String::new();
|
||||||
|
while let Some(item) = it.next() {
|
||||||
|
out.push_str(&item);
|
||||||
|
if it.peek().is_some() {
|
||||||
|
out.push_str(sep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::sync::mpsc;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
|
macro_rules! assert_contains {
|
||||||
|
($haystack:expr, $needle:expr) => {
|
||||||
|
if !$haystack.contains($needle) {
|
||||||
|
panic!("expected {:?} to contain {:?}", $haystack, $needle);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn point_manhattan_and_display() {
|
||||||
|
let p = Point { x: -3, y: 4 };
|
||||||
|
assert_eq!(p.manhattan(), 7);
|
||||||
|
assert_eq!(p.to_string(), "(-3, 4)");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn point_translate_is_pure() {
|
||||||
|
let p = Point { x: 1, y: 2 };
|
||||||
|
let q = p.translate(3, -1);
|
||||||
|
assert_eq!(p, Point { x: 1, y: 2 });
|
||||||
|
assert_eq!(q, Point { x: 4, y: 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_u8_success_and_errors() {
|
||||||
|
assert_eq!(parse_u8("0"), Ok(0));
|
||||||
|
assert_eq!(parse_u8("255"), Ok(255));
|
||||||
|
assert_eq!(parse_u8(" 17 "), Ok(17)); // leading/trailing spaces are rejected as Empty? we trimmed only emptiness, digits still parsed.
|
||||||
|
assert_eq!(parse_u8(""), Err(ParseError::Empty));
|
||||||
|
assert_eq!(parse_u8(" "), Err(ParseError::Empty));
|
||||||
|
assert_eq!(parse_u8("12a"), Err(ParseError::InvalidDigit));
|
||||||
|
assert_eq!(parse_u8("256"), Err(ParseError::TooLarge));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sum_iter_works_for_various_iterators() {
|
||||||
|
let v = vec![1, 2, 3, 4, -5];
|
||||||
|
assert_eq!(sum_iter(&v), 5);
|
||||||
|
let arr = [10i64; 4];
|
||||||
|
assert_eq!(sum_iter(arr), 40);
|
||||||
|
assert_eq!(sum_iter(0..5), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn split_once_basic_and_unicode() {
|
||||||
|
assert_eq!(split_once("a,b,c", ','), Some(("a", "b,c")));
|
||||||
|
assert_eq!(split_once("no-sep", '/'), None);
|
||||||
|
// UTF-8 needle
|
||||||
|
let s = "fooλbar";
|
||||||
|
assert_eq!(split_once(s, 'λ'), Some(("foo", "bar")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn join_with_various_lengths() {
|
||||||
|
let empty: Vec<String> = vec![];
|
||||||
|
assert_eq!(join_with(empty, ", "), "");
|
||||||
|
assert_eq!(join_with(vec!["a".into()], ", "), "a");
|
||||||
|
assert_eq!(
|
||||||
|
join_with(vec!["a".into(), "b".into(), "c".into()], "|"),
|
||||||
|
"a|b|c"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hash_map_grouping_example() {
|
||||||
|
let words = ["ant", "bat", "apple", "boat"];
|
||||||
|
let mut by_initial: HashMap<char, Vec<&str>> = HashMap::new();
|
||||||
|
for w in &words {
|
||||||
|
let key = w.chars().next().unwrap();
|
||||||
|
by_initial.entry(key).or_default().push(*w);
|
||||||
|
}
|
||||||
|
assert_eq!(by_initial.get(&'a').unwrap(), &vec!["ant", "apple"]);
|
||||||
|
assert_eq!(by_initial.get(&'b').unwrap(), &vec!["bat", "boat"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn btree_map_sorted_iteration() {
|
||||||
|
let mut map = BTreeMap::new();
|
||||||
|
map.insert("c", 3);
|
||||||
|
map.insert("a", 1);
|
||||||
|
map.insert("b", 2);
|
||||||
|
let keys: Vec<_> = map.keys().copied().collect();
|
||||||
|
assert_eq!(keys, vec!["a", "b", "c"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn channels_and_threads() {
|
||||||
|
let (tx, rx) = mpsc::channel();
|
||||||
|
thread::spawn(move || {
|
||||||
|
for i in 0..5 {
|
||||||
|
tx.send(i * i).unwrap();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let received: Vec<_> = (0..5).map(|_| rx.recv().unwrap()).collect();
|
||||||
|
assert_eq!(received, vec![0, 1, 4, 9, 16]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn interior_mutability_with_refcell() {
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Counter {
|
||||||
|
inner: RefCell<u32>,
|
||||||
|
}
|
||||||
|
impl Counter {
|
||||||
|
fn inc(&self) {
|
||||||
|
*self.inner.borrow_mut() += 1;
|
||||||
|
}
|
||||||
|
fn get(&self) -> u32 {
|
||||||
|
*self.inner.borrow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let c = Counter {
|
||||||
|
inner: RefCell::new(0),
|
||||||
|
};
|
||||||
|
c.inc();
|
||||||
|
c.inc();
|
||||||
|
assert_eq!(c.get(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_panic_on_too_large_parse() {
|
||||||
|
#[should_panic(expected = "TooLarge")]
|
||||||
|
fn check() {
|
||||||
|
parse_u8("999").unwrap();
|
||||||
|
}
|
||||||
|
check();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn result_based_test() -> Result<(), String> {
|
||||||
|
let p = Point { x: 2, y: 3 };
|
||||||
|
if p.manhattan() == 5 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err("manhattan distance mismatch".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn iterator_combinators_cover_common_paths() {
|
||||||
|
let data = vec![Some(1), None, Some(3), Some(4)];
|
||||||
|
let sum: i32 = data.iter().flatten().sum();
|
||||||
|
assert_eq!(sum, 8);
|
||||||
|
|
||||||
|
let doubled: Vec<_> = (1..=5).map(|n| n * 2).filter(|n| n % 4 == 0).collect();
|
||||||
|
assert_eq!(doubled, vec![4, 8]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pattern_matching_with_guards() {
|
||||||
|
let numbers = [-2, -1, 0, 1, 2];
|
||||||
|
let labels: Vec<_> = numbers
|
||||||
|
.iter()
|
||||||
|
.map(|n| match n {
|
||||||
|
n if *n < 0 => "neg",
|
||||||
|
0 => "zero",
|
||||||
|
n if *n % 2 == 0 => "even-pos",
|
||||||
|
_ => "odd-pos",
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
assert_eq!(labels, vec!["neg", "neg", "zero", "odd-pos", "even-pos"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn custom_macro_assert_contains() {
|
||||||
|
assert_contains!("hello world", "world");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ownership_and_borrowing_examples() {
|
||||||
|
fn takes_and_gives_back(mut v: Vec<i32>) -> Vec<i32> {
|
||||||
|
v.push(42);
|
||||||
|
v
|
||||||
|
}
|
||||||
|
let v = vec![1, 2, 3];
|
||||||
|
let v = takes_and_gives_back(v);
|
||||||
|
assert_eq!(v, vec![1, 2, 3, 42]);
|
||||||
|
|
||||||
|
let s = String::from("hi");
|
||||||
|
let len = length_of_str(&s);
|
||||||
|
assert_eq!(len, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn length_of_str(s: &str) -> usize {
|
||||||
|
s.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lifetimes_and_slices() {
|
||||||
|
fn first<'a>(xs: &'a [i32]) -> Option<&'a i32> {
|
||||||
|
xs.first()
|
||||||
|
}
|
||||||
|
let data = [10, 20, 30];
|
||||||
|
assert_eq!(first(&data), Some(&10));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn const_generics_array_sum() {
|
||||||
|
fn sum_array<const N: usize>(arr: [i32; N]) -> i32 {
|
||||||
|
arr.iter().sum()
|
||||||
|
}
|
||||||
|
assert_eq!(sum_array::<3>([1, 2, 3]), 6);
|
||||||
|
assert_eq!(sum_array([0; 5]), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn duration_and_instant_arithmetic() {
|
||||||
|
use std::time::Instant;
|
||||||
|
let start = Instant::now();
|
||||||
|
std::thread::sleep(Duration::from_millis(5));
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
assert!(elapsed >= Duration::from_millis(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn string_builder_patterns() {
|
||||||
|
let parts = ["a", "b", "c"];
|
||||||
|
let mut s = String::with_capacity(3);
|
||||||
|
for p in parts {
|
||||||
|
s.push_str(p);
|
||||||
|
}
|
||||||
|
assert_eq!(s, "abc");
|
||||||
|
assert!(s.capacity() >= 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn equality_and_ordering_on_point() {
|
||||||
|
let p1 = Point { x: 1, y: 2 };
|
||||||
|
let p2 = Point { x: 1, y: 2 };
|
||||||
|
assert_eq!(p1, p2);
|
||||||
|
assert!(p1.manhattan() <= p2.manhattan());
|
||||||
|
}
|
||||||
|
}
|
||||||
5
samples/sample.gitattributes
Normal file
5
samples/sample.gitattributes
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Sample .gitattributes file for syntax highlighting tests
|
||||||
|
|
||||||
|
*.c syntax=c
|
||||||
|
*.h syntax=c
|
||||||
|
*.py syntax=python
|
||||||
12
samples/sample.gitignore
Normal file
12
samples/sample.gitignore
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Test gitignore file (to check syntax)
|
||||||
|
|
||||||
|
*
|
||||||
|
./!
|
||||||
|
|
||||||
|
*.log
|
||||||
|
|
||||||
|
!.gitignore[2]
|
||||||
|
|
||||||
|
**/*.lo[s]g
|
||||||
|
|
||||||
|
### Comment
|
||||||
83
samples/sql.sql
Normal file
83
samples/sql.sql
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
-- Sample SQL to exercise the highlight rules
|
||||||
|
|
||||||
|
-- DDL
|
||||||
|
CREATE TEMPORARY TABLE IF NOT EXISTS public.users (
|
||||||
|
user_id BIGSERIAL PRIMARY KEY,
|
||||||
|
email VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
profile JSONB,
|
||||||
|
balance DECIMAL(12,2) DEFAULT 0.00,
|
||||||
|
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMPTZ,
|
||||||
|
CONSTRAINT email_chk CHECK (email LIKE '%@%')
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Indexes
|
||||||
|
CREATE INDEX CONCURRENTLY IF NOT EXISTS users_email_idx ON public.users USING btree (email);
|
||||||
|
CREATE INDEX IF NOT EXISTS users_profile_gin_idx ON public.users USING gin (profile);
|
||||||
|
|
||||||
|
-- Insert & returning
|
||||||
|
INSERT INTO public.users (email, profile, balance)
|
||||||
|
VALUES
|
||||||
|
('alice@example.com', '{"plan":"pro","tags":["a","b"]}'::jsonb, 25.50),
|
||||||
|
('bob@example.com', '{"plan":"free","tags":["c"]}'::jsonb, 0.00)
|
||||||
|
RETURNING user_id, email, profile;
|
||||||
|
|
||||||
|
-- Update with CASE and CAST
|
||||||
|
UPDATE public.users u
|
||||||
|
SET balance = balance + CAST(5 AS DECIMAL),
|
||||||
|
updated_at = CURRENT_TIMESTAMP,
|
||||||
|
profile = jsonb_set(profile, '{last_seen}', to_jsonb(CURRENT_TIMESTAMP)),
|
||||||
|
email = CASE
|
||||||
|
WHEN email LIKE '%@example.com' THEN replace(email, '@example.com', '@example.org')
|
||||||
|
ELSE email
|
||||||
|
END
|
||||||
|
WHERE u.balance >= 0
|
||||||
|
RETURNING user_id, email, balance;
|
||||||
|
|
||||||
|
-- Delete with USING
|
||||||
|
DELETE FROM public.users AS u
|
||||||
|
USING public.users AS t
|
||||||
|
WHERE u.user_id = t.user_id
|
||||||
|
AND u.email LIKE 'bob@%';
|
||||||
|
|
||||||
|
-- Window, CTE, aggregates
|
||||||
|
WITH recent AS (
|
||||||
|
SELECT *
|
||||||
|
FROM public.users
|
||||||
|
WHERE created_at > NOW() - INTERVAL '30 days'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
user_id,
|
||||||
|
email,
|
||||||
|
balance,
|
||||||
|
SUM(balance) OVER (PARTITION BY 1 ORDER BY created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_total,
|
||||||
|
ROW_NUMBER() OVER (ORDER BY created_at DESC) AS rn
|
||||||
|
FROM recent
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT 50 OFFSET 0;
|
||||||
|
|
||||||
|
-- Joins and JSON
|
||||||
|
CREATE TEMP TABLE events (
|
||||||
|
event_id BIGSERIAL PRIMARY KEY,
|
||||||
|
user_id BIGINT REFERENCES public.users(user_id),
|
||||||
|
payload JSONB,
|
||||||
|
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO events (user_id, payload) VALUES
|
||||||
|
(1, '{"type":"login","ip":"127.0.0.1"}'),
|
||||||
|
(1, '{"type":"purchase","amount":9.99,"items":[{"sku":"A1","qty":1}]}' ),
|
||||||
|
(2, '{"type":"login","ip":"10.0.0.2"}');
|
||||||
|
|
||||||
|
SELECT u.email, e.payload->>'type' AS event_type, e.payload
|
||||||
|
FROM public.users u
|
||||||
|
LEFT JOIN events e ON e.user_id = u.user_id
|
||||||
|
WHERE e.payload ? 'type'
|
||||||
|
ORDER BY e.created_at DESC;
|
||||||
|
|
||||||
|
-- Transaction control
|
||||||
|
BEGIN;
|
||||||
|
UPDATE public.users SET balance = balance - 5 WHERE email LIKE 'alice%';
|
||||||
|
INSERT INTO events (user_id, payload)
|
||||||
|
SELECT user_id, jsonb_build_object('type','adjust','delta',-5) FROM public.users WHERE email LIKE 'alice%';
|
||||||
|
COMMIT;
|
||||||
53
samples/toml.toml
Normal file
53
samples/toml.toml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# ============================================================
|
||||||
|
# Basic types
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
title = "Example TOML Configuration"
|
||||||
|
enabled = true
|
||||||
|
count = 42
|
||||||
|
pi = 3.14159
|
||||||
|
empty = ""
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Arrays
|
||||||
|
# ============================================================
|
||||||
|
fruits = ["apple", "banana", "cherry"]
|
||||||
|
numbers = [1, 2, 3, 4, 5]
|
||||||
|
|
||||||
|
# Nested array
|
||||||
|
matrix = [[1, 2], [3, 4]]
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Tables
|
||||||
|
# ============================================================
|
||||||
|
[owner]
|
||||||
|
name = "Alice"
|
||||||
|
dob = 1979-05-27T07:32:00Z
|
||||||
|
|
||||||
|
[database]
|
||||||
|
server = "192.168.1.1"
|
||||||
|
ports = [ 8001, 8001, 8002 ]
|
||||||
|
connection_max = 5000
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
[servers.alpha]
|
||||||
|
ip = "10.0.0.1"
|
||||||
|
dc = "east"
|
||||||
|
|
||||||
|
[servers.beta]
|
||||||
|
ip = "10.0.0.2"
|
||||||
|
dc = "west"
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Inline tables
|
||||||
|
# ============================================================
|
||||||
|
clients = { name = "Bob", age = 30, active = true }
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Multiline strings
|
||||||
|
# ============================================================
|
||||||
|
description = """
|
||||||
|
This is a TOML file
|
||||||
|
used for testing syntax highlighting.
|
||||||
|
It supports multiple lines.
|
||||||
|
"""
|
||||||
66
samples/yaml.yaml
Normal file
66
samples/yaml.yaml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# ============================================================
|
||||||
|
# Basic types
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
title: "Example YAML Configuration"
|
||||||
|
enabled: true
|
||||||
|
count: 42
|
||||||
|
pi: 3.14159
|
||||||
|
empty: ""
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Arrays / Lists
|
||||||
|
# ============================================================
|
||||||
|
fruits:
|
||||||
|
- apple
|
||||||
|
- banana
|
||||||
|
- cherry
|
||||||
|
|
||||||
|
numbers:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
- 4
|
||||||
|
- 5
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
- [1, 2]
|
||||||
|
- [3, 4]
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Nested objects / maps
|
||||||
|
# ============================================================
|
||||||
|
owner:
|
||||||
|
name: Alice
|
||||||
|
dob: 1979-05-27T07:32:00Z
|
||||||
|
|
||||||
|
database:
|
||||||
|
server: 192.168.1.1
|
||||||
|
ports:
|
||||||
|
- 8001
|
||||||
|
- 8001
|
||||||
|
- 8002
|
||||||
|
connection_max: 5000
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
servers:
|
||||||
|
alpha:
|
||||||
|
ip: 10.0.0.1
|
||||||
|
dc: east
|
||||||
|
beta:
|
||||||
|
ip: 10.0.0.2
|
||||||
|
dc: west
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Multiline string
|
||||||
|
# ============================================================
|
||||||
|
description: |
|
||||||
|
This is a YAML file
|
||||||
|
used for testing syntax highlighting.
|
||||||
|
It supports multiple lines.
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Special characters
|
||||||
|
# ============================================================
|
||||||
|
regex_pattern: "^[A-Za-z0-9_]+$"
|
||||||
|
path: "C:\\Users\\Alice\\Documents"
|
||||||
564
src/editor.cc
564
src/editor.cc
@@ -1,564 +0,0 @@
|
|||||||
extern "C" {
|
|
||||||
#include "../libs/libgrapheme/grapheme.h"
|
|
||||||
}
|
|
||||||
#include "../include/editor.h"
|
|
||||||
#include "../include/ts.h"
|
|
||||||
#include "../include/utils.h"
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
Editor *new_editor(const char *filename, Coord position, Coord size) {
|
|
||||||
Editor *editor = new Editor();
|
|
||||||
if (!editor)
|
|
||||||
return nullptr;
|
|
||||||
uint32_t len = 0;
|
|
||||||
char *str = load_file(filename, &len);
|
|
||||||
if (!str) {
|
|
||||||
free_editor(editor);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
editor->filename = filename;
|
|
||||||
editor->position = position;
|
|
||||||
editor->size = size;
|
|
||||||
editor->tree = nullptr;
|
|
||||||
editor->cursor = {0, 0};
|
|
||||||
editor->cursor_preffered = UINT32_MAX;
|
|
||||||
editor->selection_active = false;
|
|
||||||
editor->selection = {0, 0};
|
|
||||||
editor->scroll = {0, 0};
|
|
||||||
editor->root = load(str, len, optimal_chunk_size(len));
|
|
||||||
free(str);
|
|
||||||
editor->folded.resize(editor->root->line_count + 2);
|
|
||||||
if (len < (1024 * 64)) {
|
|
||||||
editor->parser = ts_parser_new();
|
|
||||||
Language language = language_for_file(filename);
|
|
||||||
editor->language = language.fn();
|
|
||||||
ts_parser_set_language(editor->parser, editor->language);
|
|
||||||
std::string query = get_exe_dir() + "/../grammar/" + language.name + ".scm";
|
|
||||||
editor->query = load_query(query.c_str(), editor);
|
|
||||||
}
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_editor(Editor *editor) {
|
|
||||||
ts_parser_delete(editor->parser);
|
|
||||||
if (editor->tree)
|
|
||||||
ts_tree_delete(editor->tree);
|
|
||||||
if (editor->query)
|
|
||||||
ts_query_delete(editor->query);
|
|
||||||
free_rope(editor->root);
|
|
||||||
delete editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scroll_up(Editor *editor, uint32_t number) {
|
|
||||||
if (!editor || !editor->root || number == 0)
|
|
||||||
return;
|
|
||||||
uint32_t count = 0;
|
|
||||||
uint32_t visible_lines_checked = 0;
|
|
||||||
int32_t current_check_row = editor->scroll.row;
|
|
||||||
while (visible_lines_checked < number + 1 && current_check_row >= 0) {
|
|
||||||
if (editor->folded[current_check_row] != 1)
|
|
||||||
visible_lines_checked++;
|
|
||||||
count++;
|
|
||||||
current_check_row--;
|
|
||||||
}
|
|
||||||
if (current_check_row < 0)
|
|
||||||
count = editor->scroll.row;
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, editor->scroll.row - count + 1);
|
|
||||||
std::vector<std::pair<uint32_t, uint32_t>> stack;
|
|
||||||
stack.reserve(count);
|
|
||||||
uint32_t lines_iterated = 0;
|
|
||||||
uint32_t start_row = editor->scroll.row - count + 1;
|
|
||||||
while (lines_iterated < count) {
|
|
||||||
char *line_content = next_line(it);
|
|
||||||
uint32_t current_idx = start_row + lines_iterated;
|
|
||||||
int fold_state = editor->folded[current_idx];
|
|
||||||
if (fold_state == 2) {
|
|
||||||
stack.push_back({1, current_idx});
|
|
||||||
} else if (fold_state == 0) {
|
|
||||||
uint32_t len =
|
|
||||||
(line_content != nullptr) ? grapheme_strlen(line_content) : 0;
|
|
||||||
stack.push_back({len, current_idx});
|
|
||||||
}
|
|
||||||
if (line_content)
|
|
||||||
free(line_content);
|
|
||||||
lines_iterated++;
|
|
||||||
}
|
|
||||||
uint32_t ln = 0;
|
|
||||||
uint32_t wrap_limit = editor->size.col;
|
|
||||||
for (int i = stack.size() - 1; i >= 0; i--) {
|
|
||||||
uint32_t len = stack[i].first;
|
|
||||||
uint32_t row_idx = stack[i].second;
|
|
||||||
uint32_t segments =
|
|
||||||
(wrap_limit > 0 && len > 0) ? (len + wrap_limit - 1) / wrap_limit : 1;
|
|
||||||
if (len == 0)
|
|
||||||
segments = 1;
|
|
||||||
for (int seg = (row_idx == editor->scroll.row)
|
|
||||||
? editor->scroll.col / wrap_limit
|
|
||||||
: segments - 1;
|
|
||||||
seg >= 0; seg--) {
|
|
||||||
ln++;
|
|
||||||
if (ln == number + 1) {
|
|
||||||
editor->scroll.row = row_idx;
|
|
||||||
editor->scroll.col = seg * wrap_limit;
|
|
||||||
free(it);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ln < number + 1) {
|
|
||||||
editor->scroll.row = 0;
|
|
||||||
editor->scroll.col = 0;
|
|
||||||
}
|
|
||||||
free(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
void scroll_down(Editor *editor, uint32_t number) {
|
|
||||||
if (!editor || !editor->root || number == 0)
|
|
||||||
return;
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, editor->scroll.row);
|
|
||||||
uint32_t current_row = editor->scroll.row;
|
|
||||||
uint32_t lines_moved = 0;
|
|
||||||
uint32_t wrap_limit = editor->size.col;
|
|
||||||
if (wrap_limit == 0)
|
|
||||||
wrap_limit = 1;
|
|
||||||
while (lines_moved < number) {
|
|
||||||
char *line_content = next_line(it);
|
|
||||||
if (line_content == nullptr)
|
|
||||||
break;
|
|
||||||
int fold_state = editor->folded[current_row];
|
|
||||||
if (fold_state == 1) {
|
|
||||||
free(line_content);
|
|
||||||
current_row++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
uint32_t segments = 1;
|
|
||||||
if (fold_state == 2) {
|
|
||||||
segments = 1;
|
|
||||||
} else {
|
|
||||||
uint32_t len = grapheme_strlen(line_content);
|
|
||||||
segments = (len > 0) ? (len + wrap_limit - 1) / wrap_limit : 1;
|
|
||||||
}
|
|
||||||
uint32_t start_seg = (current_row == editor->scroll.row)
|
|
||||||
? (editor->scroll.col / wrap_limit)
|
|
||||||
: 0;
|
|
||||||
for (uint32_t seg = start_seg; seg < segments; seg++) {
|
|
||||||
if (current_row == editor->scroll.row && seg == start_seg)
|
|
||||||
continue;
|
|
||||||
lines_moved++;
|
|
||||||
if (lines_moved == number) {
|
|
||||||
editor->scroll.row = current_row;
|
|
||||||
editor->scroll.col = seg * wrap_limit;
|
|
||||||
free(line_content);
|
|
||||||
free(it);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(line_content);
|
|
||||||
current_row++;
|
|
||||||
}
|
|
||||||
free(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cursor_down(Editor *editor, uint32_t number) {
|
|
||||||
if (!editor || !editor->root || number == 0)
|
|
||||||
return;
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
char *line_content = next_line(it);
|
|
||||||
if (line_content == nullptr)
|
|
||||||
return;
|
|
||||||
if (editor->cursor_preffered == UINT32_MAX)
|
|
||||||
editor->cursor_preffered =
|
|
||||||
get_visual_col_from_bytes(line_content, editor->cursor.col);
|
|
||||||
uint32_t visual_col = editor->cursor_preffered;
|
|
||||||
do {
|
|
||||||
free(line_content);
|
|
||||||
line_content = next_line(it);
|
|
||||||
editor->cursor.row += 1;
|
|
||||||
if (editor->cursor.row >= editor->root->line_count) {
|
|
||||||
editor->cursor.row = editor->root->line_count - 1;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
if (editor->folded[editor->cursor.row] != 0)
|
|
||||||
number++;
|
|
||||||
} while (--number > 0);
|
|
||||||
free(it);
|
|
||||||
if (line_content == nullptr)
|
|
||||||
return;
|
|
||||||
editor->cursor.col = get_bytes_from_visual_col(line_content, visual_col);
|
|
||||||
free(line_content);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cursor_up(Editor *editor, uint32_t number) {
|
|
||||||
if (!editor || !editor->root || number == 0)
|
|
||||||
return;
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
char *line_content = next_line(it);
|
|
||||||
if (!line_content) {
|
|
||||||
free(it);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (editor->cursor_preffered == UINT32_MAX)
|
|
||||||
editor->cursor_preffered =
|
|
||||||
get_visual_col_from_bytes(line_content, editor->cursor.col);
|
|
||||||
uint32_t visual_col = editor->cursor_preffered;
|
|
||||||
free(line_content);
|
|
||||||
while (number > 0 && editor->cursor.row > 0) {
|
|
||||||
editor->cursor.row--;
|
|
||||||
if (editor->folded[editor->cursor.row] != 0)
|
|
||||||
continue;
|
|
||||||
number--;
|
|
||||||
}
|
|
||||||
free(it);
|
|
||||||
it = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
line_content = next_line(it);
|
|
||||||
if (!line_content) {
|
|
||||||
free(it);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
editor->cursor.col = get_bytes_from_visual_col(line_content, visual_col);
|
|
||||||
free(line_content);
|
|
||||||
free(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cursor_right(Editor *editor, uint32_t number) {
|
|
||||||
if (!editor || !editor->root || number == 0)
|
|
||||||
return;
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
char *line = next_line(it);
|
|
||||||
free(it);
|
|
||||||
if (!line)
|
|
||||||
return;
|
|
||||||
uint32_t line_len = strlen(line);
|
|
||||||
if (line[line_len - 1] == '\n')
|
|
||||||
line[--line_len] = '\0';
|
|
||||||
while (number > 0) {
|
|
||||||
if (editor->cursor.col >= line_len) {
|
|
||||||
free(line);
|
|
||||||
line = nullptr;
|
|
||||||
uint32_t next_row = editor->cursor.row + 1;
|
|
||||||
while (next_row < editor->root->line_count &&
|
|
||||||
editor->folded[next_row] != 0)
|
|
||||||
next_row++;
|
|
||||||
if (next_row >= editor->root->line_count) {
|
|
||||||
editor->cursor.col = line_len;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
editor->cursor.row = next_row;
|
|
||||||
editor->cursor.col = 0;
|
|
||||||
it = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
line = next_line(it);
|
|
||||||
free(it);
|
|
||||||
if (!line)
|
|
||||||
break;
|
|
||||||
line_len = strlen(line);
|
|
||||||
if (line[line_len - 1] == '\n')
|
|
||||||
line[--line_len] = '\0';
|
|
||||||
} else {
|
|
||||||
uint32_t inc = grapheme_next_character_break_utf8(
|
|
||||||
line + editor->cursor.col, line_len - editor->cursor.col);
|
|
||||||
if (inc == 0)
|
|
||||||
break;
|
|
||||||
editor->cursor.col += inc;
|
|
||||||
}
|
|
||||||
number--;
|
|
||||||
}
|
|
||||||
LineIterator *it2 = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
char *cur_line = next_line(it2);
|
|
||||||
free(it2);
|
|
||||||
if (cur_line) {
|
|
||||||
uint32_t len2 = strlen(cur_line);
|
|
||||||
if (len2 > 0 && cur_line[len2 - 1] == '\n')
|
|
||||||
cur_line[--len2] = '\0';
|
|
||||||
editor->cursor_preffered =
|
|
||||||
get_visual_col_from_bytes(cur_line, editor->cursor.col);
|
|
||||||
free(cur_line);
|
|
||||||
} else {
|
|
||||||
editor->cursor_preffered = UINT32_MAX;
|
|
||||||
}
|
|
||||||
if (line)
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cursor_left(Editor *editor, uint32_t number) {
|
|
||||||
if (!editor || !editor->root || number == 0)
|
|
||||||
return;
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
char *line = next_line(it);
|
|
||||||
free(it);
|
|
||||||
if (!line)
|
|
||||||
return;
|
|
||||||
uint32_t len = strlen(line);
|
|
||||||
if (line[len - 1] == '\n')
|
|
||||||
line[--len] = '\0';
|
|
||||||
while (number > 0) {
|
|
||||||
if (editor->cursor.col == 0) {
|
|
||||||
free(line);
|
|
||||||
line = nullptr;
|
|
||||||
if (editor->cursor.row == 0)
|
|
||||||
break;
|
|
||||||
int32_t prev_row = editor->cursor.row - 1;
|
|
||||||
while (prev_row >= 0 && editor->folded[prev_row] != 0)
|
|
||||||
prev_row--;
|
|
||||||
if (prev_row < 0)
|
|
||||||
break;
|
|
||||||
editor->cursor.row = prev_row;
|
|
||||||
it = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
line = next_line(it);
|
|
||||||
free(it);
|
|
||||||
if (!line)
|
|
||||||
break;
|
|
||||||
uint32_t len = strlen(line);
|
|
||||||
if (line[len - 1] == '\n')
|
|
||||||
line[--len] = '\0';
|
|
||||||
editor->cursor.col = len;
|
|
||||||
} else {
|
|
||||||
uint32_t col = editor->cursor.col;
|
|
||||||
uint32_t new_col = 0;
|
|
||||||
uint32_t visual_col = 0;
|
|
||||||
uint32_t len = strlen(line);
|
|
||||||
while (new_col < col) {
|
|
||||||
uint32_t inc =
|
|
||||||
grapheme_next_character_break_utf8(line + new_col, len - new_col);
|
|
||||||
if (new_col + inc >= col)
|
|
||||||
break;
|
|
||||||
new_col += inc;
|
|
||||||
visual_col++;
|
|
||||||
}
|
|
||||||
editor->cursor.col = new_col;
|
|
||||||
}
|
|
||||||
number--;
|
|
||||||
}
|
|
||||||
LineIterator *it2 = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
char *cur_line = next_line(it2);
|
|
||||||
free(it2);
|
|
||||||
if (cur_line) {
|
|
||||||
uint32_t len2 = strlen(cur_line);
|
|
||||||
if (len2 > 0 && cur_line[len2 - 1] == '\n')
|
|
||||||
cur_line[--len2] = '\0';
|
|
||||||
editor->cursor_preffered =
|
|
||||||
get_visual_col_from_bytes(cur_line, editor->cursor.col);
|
|
||||||
free(cur_line);
|
|
||||||
} else {
|
|
||||||
editor->cursor_preffered = UINT32_MAX;
|
|
||||||
}
|
|
||||||
if (line)
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ensure_scroll(Editor *editor) {
|
|
||||||
if (editor->cursor.row < editor->scroll.row) {
|
|
||||||
uint32_t visual_delta = 0;
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
|
||||||
for (uint32_t i = editor->cursor.row; i < editor->scroll.row; i++) {
|
|
||||||
char *line = next_line(it);
|
|
||||||
if (!line)
|
|
||||||
break;
|
|
||||||
uint32_t len = grapheme_strlen(line);
|
|
||||||
visual_delta += (len + editor->size.col - 1) / editor->size.col;
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
free(it);
|
|
||||||
scroll_up(editor, visual_delta);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uint32_t current_visual_y = 0;
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, editor->scroll.row);
|
|
||||||
uint32_t i = editor->scroll.row;
|
|
||||||
char *line = nullptr;
|
|
||||||
bool found_cursor = false;
|
|
||||||
while ((line = next_line(it)) != nullptr) {
|
|
||||||
uint32_t lines_in_chunk;
|
|
||||||
uint32_t offset = (i == editor->scroll.row) ? editor->scroll.col : 0;
|
|
||||||
if (i == editor->cursor.row) {
|
|
||||||
uint32_t cursor_sub_row = editor->cursor.col / editor->size.col;
|
|
||||||
if (i == editor->scroll.row)
|
|
||||||
cursor_sub_row -= offset / editor->size.col;
|
|
||||||
current_visual_y += cursor_sub_row;
|
|
||||||
found_cursor = true;
|
|
||||||
free(line);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
uint32_t len = grapheme_strlen(line);
|
|
||||||
uint32_t visible_len = len - offset;
|
|
||||||
if (visible_len == 0)
|
|
||||||
visible_len = 1;
|
|
||||||
lines_in_chunk = (visible_len + editor->size.col - 1) / editor->size.col;
|
|
||||||
current_visual_y += lines_in_chunk;
|
|
||||||
free(line);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
free(it);
|
|
||||||
if (found_cursor)
|
|
||||||
if (current_visual_y >= editor->size.row) {
|
|
||||||
uint32_t needed_scroll = current_visual_y - editor->size.row + 1;
|
|
||||||
scroll_down(editor, needed_scroll);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void fold(Editor *editor, uint32_t start_line, uint32_t end_line) {
|
|
||||||
if (!editor)
|
|
||||||
return;
|
|
||||||
for (uint32_t i = start_line; i <= end_line && i < editor->size.row; i++)
|
|
||||||
editor->folded[i] = 1;
|
|
||||||
editor->folded[start_line] = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void update_render_fold_marker(uint32_t row, uint32_t cols) {
|
|
||||||
const char *marker = "... folded ...";
|
|
||||||
uint32_t len = strlen(marker);
|
|
||||||
uint32_t i = 0;
|
|
||||||
for (; i < len && i < cols; i++)
|
|
||||||
update(row, i, (char[2]){marker[i], 0}, 0xc6c6c6, 0, 0);
|
|
||||||
for (; i < cols; i++)
|
|
||||||
update(row, i, " ", 0xc6c6c6, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void apply_edit(std::vector<Span> &spans, uint32_t x, int64_t y) {
|
|
||||||
Span key{.start = x, .end = 0, .hl = nullptr};
|
|
||||||
auto it = std::lower_bound(
|
|
||||||
spans.begin(), spans.end(), key,
|
|
||||||
[](const Span &a, const Span &b) { return a.start < b.start; });
|
|
||||||
size_t idx = std::distance(spans.begin(), it);
|
|
||||||
while (idx > 0 && spans.at(idx - 1).end > x)
|
|
||||||
--idx;
|
|
||||||
for (size_t i = idx; i < spans.size();) {
|
|
||||||
Span &s = spans.at(i);
|
|
||||||
if (s.start < x && s.end > x) {
|
|
||||||
s.end += y;
|
|
||||||
} else if (s.start > x) {
|
|
||||||
s.start += y;
|
|
||||||
s.end += y;
|
|
||||||
}
|
|
||||||
if (s.end <= s.start)
|
|
||||||
spans.erase(spans.begin() + i);
|
|
||||||
else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void render_editor(Editor *editor) {
|
|
||||||
Coord cursor = {UINT32_MAX, UINT32_MAX};
|
|
||||||
uint32_t line_index = editor->scroll.row;
|
|
||||||
SpanCursor span_cursor(editor->spans);
|
|
||||||
std::shared_lock knot_lock(editor->knot_mtx);
|
|
||||||
LineIterator *it = begin_l_iter(editor->root, line_index);
|
|
||||||
if (!it)
|
|
||||||
return;
|
|
||||||
uint32_t rendered_rows = 0;
|
|
||||||
uint32_t global_byte_offset = line_to_byte(editor->root, line_index, nullptr);
|
|
||||||
span_cursor.sync(global_byte_offset);
|
|
||||||
while (rendered_rows < editor->size.row) {
|
|
||||||
if (editor->folded[line_index]) {
|
|
||||||
if (editor->folded[line_index] == 2) {
|
|
||||||
update_render_fold_marker(rendered_rows, editor->size.col);
|
|
||||||
rendered_rows++;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
char *line = next_line(it);
|
|
||||||
if (!line)
|
|
||||||
break;
|
|
||||||
global_byte_offset += strlen(line);
|
|
||||||
if (line[strlen(line) - 1] == '\n')
|
|
||||||
global_byte_offset--;
|
|
||||||
global_byte_offset++;
|
|
||||||
free(line);
|
|
||||||
line_index++;
|
|
||||||
} while (line_index < editor->size.row &&
|
|
||||||
editor->folded[line_index] == 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
char *line = next_line(it);
|
|
||||||
if (!line)
|
|
||||||
break;
|
|
||||||
uint32_t line_len = strlen(line);
|
|
||||||
if (line_len > 0 && line[line_len - 1] == '\n')
|
|
||||||
line_len--;
|
|
||||||
uint32_t current_byte_offset = 0;
|
|
||||||
if (rendered_rows == 0 && editor->scroll.col > 0) {
|
|
||||||
uint32_t skipped_cols = 0;
|
|
||||||
while (skipped_cols < editor->scroll.col &&
|
|
||||||
current_byte_offset < line_len) {
|
|
||||||
uint32_t len = grapheme_next_character_break_utf8(
|
|
||||||
line + current_byte_offset, line_len - current_byte_offset);
|
|
||||||
current_byte_offset += len;
|
|
||||||
skipped_cols++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (current_byte_offset < line_len && rendered_rows < editor->size.row) {
|
|
||||||
uint32_t slice_byte_len = 0;
|
|
||||||
uint32_t slice_visual_cols = 0;
|
|
||||||
uint32_t probe_offset = current_byte_offset;
|
|
||||||
while (slice_visual_cols < editor->size.col && probe_offset < line_len) {
|
|
||||||
uint32_t len = grapheme_next_character_break_utf8(
|
|
||||||
line + probe_offset, line_len - probe_offset);
|
|
||||||
slice_byte_len += len;
|
|
||||||
probe_offset += len;
|
|
||||||
slice_visual_cols++;
|
|
||||||
}
|
|
||||||
uint32_t col = 0;
|
|
||||||
uint32_t local_render_offset = 0;
|
|
||||||
while (local_render_offset < slice_byte_len) {
|
|
||||||
if (line_index == editor->cursor.row &&
|
|
||||||
editor->cursor.col == (current_byte_offset + local_render_offset)) {
|
|
||||||
cursor.row = editor->position.row + rendered_rows;
|
|
||||||
cursor.col = editor->position.col + col;
|
|
||||||
}
|
|
||||||
uint32_t absolute_byte_pos =
|
|
||||||
global_byte_offset + current_byte_offset + local_render_offset;
|
|
||||||
Highlight *hl = span_cursor.get_highlight(absolute_byte_pos);
|
|
||||||
uint32_t fg = hl ? hl->fg : 0xFFFFFF;
|
|
||||||
uint32_t bg = hl ? hl->bg : 0;
|
|
||||||
uint8_t fl = hl ? hl->flags : 0;
|
|
||||||
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
|
||||||
line + current_byte_offset + local_render_offset,
|
|
||||||
slice_byte_len - local_render_offset);
|
|
||||||
if (cluster_len == 0)
|
|
||||||
cluster_len = 1;
|
|
||||||
std::string cluster(line + current_byte_offset + local_render_offset,
|
|
||||||
cluster_len);
|
|
||||||
update(editor->position.row + rendered_rows, editor->position.col + col,
|
|
||||||
cluster.c_str(), fg, bg, fl);
|
|
||||||
local_render_offset += cluster_len;
|
|
||||||
col++;
|
|
||||||
}
|
|
||||||
if (line_index == editor->cursor.row &&
|
|
||||||
editor->cursor.col == (current_byte_offset + slice_byte_len)) {
|
|
||||||
cursor.row = editor->position.row + rendered_rows;
|
|
||||||
cursor.col = editor->position.col + col;
|
|
||||||
}
|
|
||||||
while (col < editor->size.col) {
|
|
||||||
update(editor->position.row + rendered_rows, editor->position.col + col,
|
|
||||||
" ", 0xFFFFFF, 0, 0);
|
|
||||||
col++;
|
|
||||||
}
|
|
||||||
rendered_rows++;
|
|
||||||
current_byte_offset += slice_byte_len;
|
|
||||||
}
|
|
||||||
if (line_len == 0 ||
|
|
||||||
(current_byte_offset >= line_len && rendered_rows == 0)) {
|
|
||||||
if (editor->cursor.row == line_index) {
|
|
||||||
cursor.row = editor->position.row + rendered_rows;
|
|
||||||
cursor.col = editor->position.col;
|
|
||||||
}
|
|
||||||
uint32_t col = 0;
|
|
||||||
while (col < editor->size.col) {
|
|
||||||
update(editor->position.row + rendered_rows, editor->position.col + col,
|
|
||||||
" ", 0xFFFFFF, 0, 0);
|
|
||||||
col++;
|
|
||||||
}
|
|
||||||
rendered_rows++;
|
|
||||||
}
|
|
||||||
global_byte_offset += line_len + 1;
|
|
||||||
line_index++;
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
if (cursor.row != UINT32_MAX && cursor.col != UINT32_MAX)
|
|
||||||
set_cursor(cursor.row, cursor.col, 1);
|
|
||||||
while (rendered_rows < editor->size.row) {
|
|
||||||
for (uint32_t col = 0; col < editor->size.col; col++)
|
|
||||||
update(editor->position.row + rendered_rows, editor->position.col + col,
|
|
||||||
" ", 0xFFFFFF, 0, 0);
|
|
||||||
rendered_rows++;
|
|
||||||
}
|
|
||||||
free(it);
|
|
||||||
}
|
|
||||||
195
src/editor/adjustment.cc
Normal file
195
src/editor/adjustment.cc
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
|
||||||
|
void ensure_cursor(Editor *editor) {
|
||||||
|
std::shared_lock knot_lock(editor->knot_mtx);
|
||||||
|
if (editor->cursor < editor->scroll) {
|
||||||
|
editor->cursor.row = editor->scroll.row;
|
||||||
|
editor->cursor.col = editor->scroll.col;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t numlen =
|
||||||
|
EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1));
|
||||||
|
uint32_t render_width = editor->size.col - numlen;
|
||||||
|
uint32_t visual_rows = 0;
|
||||||
|
uint32_t line_index = editor->scroll.row;
|
||||||
|
bool first_visual_line = true;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, line_index);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
Coord last_visible = editor->scroll;
|
||||||
|
while (true) {
|
||||||
|
if (visual_rows >= editor->size.row)
|
||||||
|
break;
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
uint32_t offset = first_visual_line ? editor->scroll.col : 0;
|
||||||
|
first_visual_line = false;
|
||||||
|
while (offset < line_len || (line_len == 0 && offset == 0)) {
|
||||||
|
Coord current = {line_index, offset};
|
||||||
|
last_visible = current;
|
||||||
|
visual_rows++;
|
||||||
|
if (visual_rows >= editor->size.row)
|
||||||
|
break;
|
||||||
|
uint32_t col = 0;
|
||||||
|
uint32_t advance = 0;
|
||||||
|
uint32_t left = line_len - offset;
|
||||||
|
while (left > 0 && col < render_width) {
|
||||||
|
uint32_t g =
|
||||||
|
grapheme_next_character_break_utf8(line + offset + advance, left);
|
||||||
|
int w = display_width(line + offset + advance, g);
|
||||||
|
if (col + w > render_width)
|
||||||
|
break;
|
||||||
|
advance += g;
|
||||||
|
left -= g;
|
||||||
|
col += w;
|
||||||
|
}
|
||||||
|
if (line_index == editor->cursor.row) {
|
||||||
|
if (editor->cursor.col >= offset &&
|
||||||
|
editor->cursor.col <= offset + advance) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (advance == 0)
|
||||||
|
break;
|
||||||
|
offset += advance;
|
||||||
|
if (line_len == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
line_index++;
|
||||||
|
}
|
||||||
|
editor->cursor.row = last_visible.row;
|
||||||
|
editor->cursor.col = last_visible.col;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ensure_scroll(Editor *editor) {
|
||||||
|
std::shared_lock knot_lock(editor->knot_mtx);
|
||||||
|
uint32_t numlen =
|
||||||
|
EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1));
|
||||||
|
uint32_t render_width = editor->size.col - numlen;
|
||||||
|
if (editor->cursor < editor->scroll) {
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
uint32_t cols = 0;
|
||||||
|
uint32_t offset = 0;
|
||||||
|
uint32_t old_offset = 0;
|
||||||
|
while (offset < len) {
|
||||||
|
uint32_t inc =
|
||||||
|
grapheme_next_character_break_utf8(line + offset, len - offset);
|
||||||
|
int width = display_width(line + offset, inc);
|
||||||
|
if (cols + width > render_width) {
|
||||||
|
cols = 0;
|
||||||
|
if (editor->cursor.col > old_offset && editor->cursor.col <= offset) {
|
||||||
|
editor->scroll.row = editor->cursor.row;
|
||||||
|
editor->scroll.col = old_offset;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
old_offset = offset;
|
||||||
|
}
|
||||||
|
cols += width;
|
||||||
|
offset += inc;
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
editor->scroll.row = editor->cursor.row;
|
||||||
|
editor->scroll.col = (editor->cursor.col == 0) ? 0 : old_offset;
|
||||||
|
} else if (editor->cursor.row - editor->scroll.row < editor->size.row * 2) {
|
||||||
|
uint32_t line_index = editor->scroll.row;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, line_index);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t max_visual_lines = editor->size.row;
|
||||||
|
Coord *scroll_queue = (Coord *)malloc(sizeof(Coord) * max_visual_lines);
|
||||||
|
uint32_t q_head = 0;
|
||||||
|
uint32_t q_size = 0;
|
||||||
|
bool first_visual_line = true;
|
||||||
|
while (true) {
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
uint32_t current_byte_offset = 0;
|
||||||
|
if (first_visual_line) {
|
||||||
|
current_byte_offset += editor->scroll.col;
|
||||||
|
first_visual_line = false;
|
||||||
|
}
|
||||||
|
while (current_byte_offset < line_len ||
|
||||||
|
(line_len == 0 && current_byte_offset == 0)) {
|
||||||
|
Coord current_coord = {line_index, current_byte_offset};
|
||||||
|
if (q_size < max_visual_lines) {
|
||||||
|
scroll_queue[(q_head + q_size) % max_visual_lines] = current_coord;
|
||||||
|
q_size++;
|
||||||
|
} else {
|
||||||
|
scroll_queue[q_head] = current_coord;
|
||||||
|
q_head = (q_head + 1) % max_visual_lines;
|
||||||
|
}
|
||||||
|
uint32_t col = 0;
|
||||||
|
uint32_t local_render_offset = 0;
|
||||||
|
uint32_t line_left = line_len - current_byte_offset;
|
||||||
|
while (line_left > 0 && col < render_width) {
|
||||||
|
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
||||||
|
line + current_byte_offset + local_render_offset, line_left);
|
||||||
|
int width = display_width(
|
||||||
|
line + current_byte_offset + local_render_offset, cluster_len);
|
||||||
|
if (col + width > render_width)
|
||||||
|
break;
|
||||||
|
local_render_offset += cluster_len;
|
||||||
|
line_left -= cluster_len;
|
||||||
|
col += width;
|
||||||
|
}
|
||||||
|
if (line_index == editor->cursor.row) {
|
||||||
|
bool cursor_found = false;
|
||||||
|
if (editor->cursor.col >= current_byte_offset &&
|
||||||
|
editor->cursor.col < current_byte_offset + local_render_offset)
|
||||||
|
cursor_found = true;
|
||||||
|
else if (editor->cursor.col == line_len &&
|
||||||
|
current_byte_offset + local_render_offset == line_len)
|
||||||
|
cursor_found = true;
|
||||||
|
if (cursor_found) {
|
||||||
|
editor->scroll = scroll_queue[q_head];
|
||||||
|
free(scroll_queue);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current_byte_offset += local_render_offset;
|
||||||
|
if (line_len == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
line_index++;
|
||||||
|
}
|
||||||
|
free(scroll_queue);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
} else {
|
||||||
|
editor->scroll.row = (editor->cursor.row > editor->size.row * 1.5)
|
||||||
|
? editor->cursor.row - editor->size.row * 1.5
|
||||||
|
: 0;
|
||||||
|
editor->scroll.col = 0;
|
||||||
|
ensure_scroll(editor);
|
||||||
|
}
|
||||||
|
}
|
||||||
118
src/editor/boundaries.cc
Normal file
118
src/editor/boundaries.cc
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
|
||||||
|
uint32_t scan_left(const char *line, uint32_t len, uint32_t off) {
|
||||||
|
if (off > len)
|
||||||
|
off = len;
|
||||||
|
uint32_t i = off;
|
||||||
|
while (i > 0) {
|
||||||
|
unsigned char c = (unsigned char)line[i - 1];
|
||||||
|
if ((c & 0x80) != 0)
|
||||||
|
break;
|
||||||
|
if (!((c == '_') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') ||
|
||||||
|
(c >= 'a' && c <= 'z')))
|
||||||
|
break;
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t scan_right(const char *line, uint32_t len, uint32_t off) {
|
||||||
|
if (off > len)
|
||||||
|
off = len;
|
||||||
|
uint32_t i = off;
|
||||||
|
while (i < len) {
|
||||||
|
unsigned char c = (unsigned char)line[i];
|
||||||
|
if ((c & 0x80) != 0)
|
||||||
|
break;
|
||||||
|
if (!((c == '_') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') ||
|
||||||
|
(c >= 'a' && c <= 'z')))
|
||||||
|
break;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void word_boundaries_exclusive(Editor *editor, Coord coord, uint32_t *prev_col,
|
||||||
|
uint32_t *next_col) {
|
||||||
|
if (!editor)
|
||||||
|
return;
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, coord.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (line_len && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
uint32_t col = coord.col;
|
||||||
|
if (col > line_len)
|
||||||
|
col = line_len;
|
||||||
|
uint32_t left = scan_left(line, line_len, col);
|
||||||
|
uint32_t right = scan_right(line, line_len, col);
|
||||||
|
if (prev_col)
|
||||||
|
*prev_col = left;
|
||||||
|
if (next_col)
|
||||||
|
*next_col = right;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t word_jump_right(const char *line, size_t len, uint32_t pos) {
|
||||||
|
if (pos >= len)
|
||||||
|
return len;
|
||||||
|
size_t next = grapheme_next_word_break_utf8(line + pos, len - pos);
|
||||||
|
return static_cast<uint32_t>(pos + next);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t word_jump_left(const char *line, size_t len, uint32_t col) {
|
||||||
|
if (col == 0)
|
||||||
|
return 0;
|
||||||
|
size_t pos = 0;
|
||||||
|
size_t last = 0;
|
||||||
|
size_t cursor = col;
|
||||||
|
while (pos < len) {
|
||||||
|
size_t next = pos + grapheme_next_word_break_utf8(line + pos, len - pos);
|
||||||
|
if (next >= cursor)
|
||||||
|
break;
|
||||||
|
last = next;
|
||||||
|
pos = next;
|
||||||
|
}
|
||||||
|
return static_cast<uint32_t>(last);
|
||||||
|
}
|
||||||
|
|
||||||
|
void word_boundaries(Editor *editor, Coord coord, uint32_t *prev_col,
|
||||||
|
uint32_t *next_col, uint32_t *prev_clusters,
|
||||||
|
uint32_t *next_clusters) {
|
||||||
|
if (!editor)
|
||||||
|
return;
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, coord.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
return;
|
||||||
|
if (line_len && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
size_t col = coord.col;
|
||||||
|
if (col > line_len)
|
||||||
|
col = line_len;
|
||||||
|
size_t left = word_jump_left(line, line_len, col);
|
||||||
|
size_t right = word_jump_right(line, line_len, col);
|
||||||
|
if (prev_col)
|
||||||
|
*prev_col = static_cast<uint32_t>(left);
|
||||||
|
if (next_col)
|
||||||
|
*next_col = static_cast<uint32_t>(right);
|
||||||
|
if (prev_clusters)
|
||||||
|
*prev_clusters = count_clusters(line, line_len, left, col);
|
||||||
|
if (next_clusters)
|
||||||
|
*next_clusters = count_clusters(line, line_len, col, right);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
73
src/editor/click.cc
Normal file
73
src/editor/click.cc
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
Coord editor_hit_test(Editor *editor, uint32_t x, uint32_t y) {
|
||||||
|
if (mode == INSERT)
|
||||||
|
x++;
|
||||||
|
uint32_t numlen =
|
||||||
|
EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1));
|
||||||
|
uint32_t render_width = editor->size.col - numlen;
|
||||||
|
x = MAX(x, numlen) - numlen;
|
||||||
|
uint32_t target_visual_row = y;
|
||||||
|
uint32_t visual_row = 0;
|
||||||
|
uint32_t line_index = editor->scroll.row;
|
||||||
|
uint32_t last_line_index = editor->scroll.row;
|
||||||
|
uint32_t last_col = editor->scroll.col;
|
||||||
|
bool first_visual_line = true;
|
||||||
|
std::shared_lock knot_lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, line_index);
|
||||||
|
if (!it)
|
||||||
|
return editor->scroll;
|
||||||
|
while (visual_row <= target_visual_row) {
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
if (line_len && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
last_line_index = line_index;
|
||||||
|
last_col = line_len;
|
||||||
|
uint32_t offset = first_visual_line ? editor->scroll.col : 0;
|
||||||
|
first_visual_line = false;
|
||||||
|
while (offset < line_len || (line_len == 0 && offset == 0)) {
|
||||||
|
uint32_t col = 0;
|
||||||
|
uint32_t advance = 0;
|
||||||
|
uint32_t left = line_len - offset;
|
||||||
|
uint32_t last_good_offset = offset;
|
||||||
|
while (left > 0 && col < render_width) {
|
||||||
|
uint32_t g =
|
||||||
|
grapheme_next_character_break_utf8(line + offset + advance, left);
|
||||||
|
int w = display_width(line + offset + advance, g);
|
||||||
|
if (col + w > render_width)
|
||||||
|
break;
|
||||||
|
if (visual_row == target_visual_row && x < col + w) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return {line_index, offset + advance};
|
||||||
|
}
|
||||||
|
advance += g;
|
||||||
|
last_good_offset = offset + advance;
|
||||||
|
left -= g;
|
||||||
|
col += w;
|
||||||
|
}
|
||||||
|
last_col = last_good_offset;
|
||||||
|
if (visual_row == target_visual_row) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return {line_index, last_good_offset};
|
||||||
|
}
|
||||||
|
visual_row++;
|
||||||
|
if (visual_row > target_visual_row)
|
||||||
|
break;
|
||||||
|
if (advance == 0)
|
||||||
|
break;
|
||||||
|
offset += advance;
|
||||||
|
if (line_len == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
line_index++;
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return {last_line_index, last_col};
|
||||||
|
}
|
||||||
461
src/editor/completions.cc
Normal file
461
src/editor/completions.cc
Normal file
@@ -0,0 +1,461 @@
|
|||||||
|
#include "editor/decl.h"
|
||||||
|
#include "editor/editor.h"
|
||||||
|
#include "io/knot.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "lsp/lsp.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
inline static std::string completion_prefix(Editor *editor) {
|
||||||
|
Coord hook = editor->completion.hook;
|
||||||
|
Coord cur = editor->cursor;
|
||||||
|
if (hook.row != cur.row || cur.col < hook.col)
|
||||||
|
return "";
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, hook.row);
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::string prefix(line + hook.col, cur.col - hook.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void completion_adjust_scroll(CompletionSession &s) {
|
||||||
|
if (s.visible.empty())
|
||||||
|
return;
|
||||||
|
int vi = -1;
|
||||||
|
for (size_t i = 0; i < s.visible.size(); i++)
|
||||||
|
if (s.visible[i] == s.select) {
|
||||||
|
vi = (int)i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (vi < 0)
|
||||||
|
return;
|
||||||
|
if ((uint32_t)vi < s.scroll)
|
||||||
|
s.scroll = vi;
|
||||||
|
else if ((uint32_t)vi >= s.scroll + 8)
|
||||||
|
s.scroll = vi - 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
void completion_filter(Editor *editor) {
|
||||||
|
auto &session = editor->completion;
|
||||||
|
std::string prefix = completion_prefix(editor);
|
||||||
|
session.visible.clear();
|
||||||
|
for (size_t i = 0; i < session.items.size(); ++i) {
|
||||||
|
const auto &item = session.items[i];
|
||||||
|
const std::string &key = item.filter;
|
||||||
|
if (key.size() >= prefix.size() &&
|
||||||
|
key.compare(0, prefix.size(), prefix) == 0)
|
||||||
|
session.visible.push_back(i);
|
||||||
|
}
|
||||||
|
if (session.visible.empty()) {
|
||||||
|
session.box.hidden = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (std::find(session.visible.begin(), session.visible.end(),
|
||||||
|
session.select) == session.visible.end())
|
||||||
|
session.select = session.visible[0];
|
||||||
|
session.box.hidden = false;
|
||||||
|
session.scroll = 0;
|
||||||
|
completion_adjust_scroll(session);
|
||||||
|
session.box.render_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void completion_request(Editor *editor) {
|
||||||
|
Coord hook = editor->cursor;
|
||||||
|
word_boundaries(editor, editor->cursor, &hook.col, nullptr, nullptr, nullptr);
|
||||||
|
editor->completion.hook = hook;
|
||||||
|
editor->completion.complete = false;
|
||||||
|
editor->completion.active = false;
|
||||||
|
editor->completion.items.clear();
|
||||||
|
editor->completion.visible.clear();
|
||||||
|
editor->completion.select = 0;
|
||||||
|
editor->completion.version = editor->lsp_version;
|
||||||
|
LSPPending *pending = new LSPPending();
|
||||||
|
pending->editor = editor;
|
||||||
|
pending->method = "textDocument/completion";
|
||||||
|
pending->callback = [](Editor *editor, std::string, json message) {
|
||||||
|
auto &session = editor->completion;
|
||||||
|
std::unique_lock lock(session.mtx);
|
||||||
|
std::vector<json> items_json;
|
||||||
|
std::vector<char> end_chars_def;
|
||||||
|
int insert_text_format = 1;
|
||||||
|
int insert_text_mode = 1;
|
||||||
|
if (message.contains("result")) {
|
||||||
|
auto &result = message["result"];
|
||||||
|
if (result.is_array()) {
|
||||||
|
items_json = result.get<std::vector<json>>();
|
||||||
|
session.complete = true;
|
||||||
|
if (items_json.empty())
|
||||||
|
return;
|
||||||
|
editor->completion.active = true;
|
||||||
|
} else if (result.is_object() && result.contains("items")) {
|
||||||
|
auto &list = result;
|
||||||
|
items_json = list["items"].get<std::vector<json>>();
|
||||||
|
if (items_json.empty())
|
||||||
|
return;
|
||||||
|
editor->completion.active = true;
|
||||||
|
session.complete = !list.value("isIncomplete", false);
|
||||||
|
if (list.contains("itemDefaults") && list["itemDefaults"].is_object()) {
|
||||||
|
auto &defs = list["itemDefaults"];
|
||||||
|
if (defs.contains("insertTextFormat") &&
|
||||||
|
defs["insertTextFormat"].is_number())
|
||||||
|
insert_text_format = defs["insertTextFormat"].get<int>();
|
||||||
|
if (defs.contains("insertTextMode") &&
|
||||||
|
defs["insertTextMode"].is_number())
|
||||||
|
insert_text_mode = defs["insertTextMode"].get<int>();
|
||||||
|
if (defs.contains("textEdit"))
|
||||||
|
if (defs["textEdit"].is_array())
|
||||||
|
for (auto &c : defs["textEdit"]) {
|
||||||
|
if (!c.is_string())
|
||||||
|
continue;
|
||||||
|
std::string str = c.get<std::string>();
|
||||||
|
if (str.size() != 1)
|
||||||
|
continue;
|
||||||
|
end_chars_def.push_back(str[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.items.reserve(items_json.size() + 1);
|
||||||
|
session.visible.reserve(items_json.size() + 1);
|
||||||
|
for (auto &item_json : items_json) {
|
||||||
|
CompletionItem item;
|
||||||
|
item.original = item_json;
|
||||||
|
item.label = item_json.value("label", "");
|
||||||
|
item.kind = item_json.value("kind", 0);
|
||||||
|
if (item_json.contains("detail") && item_json["detail"].is_string())
|
||||||
|
item.detail = item_json["detail"].get<std::string>();
|
||||||
|
if (item_json.contains("documentation")) {
|
||||||
|
if (item_json["documentation"].is_string()) {
|
||||||
|
item.documentation = item_json["documentation"].get<std::string>();
|
||||||
|
} else if (item_json["documentation"].contains("value") &&
|
||||||
|
item_json["documentation"]["value"].is_string()) {
|
||||||
|
item.is_markup =
|
||||||
|
item_json["documentation"]["kind"].get<std::string>() ==
|
||||||
|
"markdown";
|
||||||
|
std::string documentation =
|
||||||
|
item_json["documentation"]["value"].get<std::string>();
|
||||||
|
if (documentation.size() > 1024)
|
||||||
|
item.is_markup = false;
|
||||||
|
if (item.is_markup) {
|
||||||
|
item.documentation =
|
||||||
|
substitute_fence(documentation, editor->lang.name);
|
||||||
|
} else {
|
||||||
|
item.documentation = documentation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item_json.contains("deprecated") &&
|
||||||
|
item_json["deprecated"].is_boolean())
|
||||||
|
item.deprecated = item_json["deprecated"].get<bool>();
|
||||||
|
auto tags = item_json.value("tags", std::vector<int>());
|
||||||
|
for (auto tag : tags)
|
||||||
|
if (tag == 1)
|
||||||
|
item.deprecated = true;
|
||||||
|
item.sort = item_json.value("sortText", item.label);
|
||||||
|
item.filter = item_json.value("filterText", item.label);
|
||||||
|
if (item_json.contains("preselect") &&
|
||||||
|
item_json["preselect"].is_boolean() &&
|
||||||
|
item_json["preselect"].get<bool>())
|
||||||
|
session.select = session.items.size() - 1;
|
||||||
|
TextEdit edit;
|
||||||
|
if (item_json.contains("textEdit")) {
|
||||||
|
auto &te = item_json["textEdit"];
|
||||||
|
if (te.contains("newText")) {
|
||||||
|
edit.text = te.value("newText", "");
|
||||||
|
if (te.contains("replace")) {
|
||||||
|
edit.start.row = te["replace"]["start"]["line"];
|
||||||
|
edit.start.col = te["replace"]["start"]["character"];
|
||||||
|
edit.end.row = te["replace"]["end"]["line"];
|
||||||
|
edit.end.col = te["replace"]["end"]["character"];
|
||||||
|
} else if (te.contains("insert")) {
|
||||||
|
edit.start.row = te["insert"]["start"]["line"];
|
||||||
|
edit.start.col = te["insert"]["start"]["character"];
|
||||||
|
edit.end.row = te["insert"]["end"]["line"];
|
||||||
|
edit.end.col = te["insert"]["end"]["character"];
|
||||||
|
} else if (te.contains("range")) {
|
||||||
|
edit.start.row = te["range"]["start"]["line"];
|
||||||
|
edit.start.col = te["range"]["start"]["character"];
|
||||||
|
edit.end.row = te["range"]["end"]["line"];
|
||||||
|
edit.end.col = te["range"]["end"]["character"];
|
||||||
|
} else {
|
||||||
|
edit.start = session.hook;
|
||||||
|
edit.end = editor->cursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (item_json.contains("insertText") &&
|
||||||
|
item_json["insertText"].is_string()) {
|
||||||
|
edit.text = item_json["insertText"].get<std::string>();
|
||||||
|
edit.start = session.hook;
|
||||||
|
edit.end = editor->cursor;
|
||||||
|
} else {
|
||||||
|
edit.text = item.label;
|
||||||
|
edit.start = session.hook;
|
||||||
|
edit.end = editor->cursor;
|
||||||
|
}
|
||||||
|
utf8_normalize_edit(editor, &edit);
|
||||||
|
item.edits.push_back(edit);
|
||||||
|
if (item_json.contains("additionalTextEdits")) {
|
||||||
|
for (auto &te : item_json["additionalTextEdits"]) {
|
||||||
|
TextEdit edit;
|
||||||
|
edit.text = te.value("newText", "");
|
||||||
|
edit.start.row = te["range"]["start"]["line"];
|
||||||
|
edit.start.col = te["range"]["start"]["character"];
|
||||||
|
edit.end.row = te["range"]["end"]["line"];
|
||||||
|
edit.end.col = te["range"]["end"]["character"];
|
||||||
|
utf8_normalize_edit(editor, &edit);
|
||||||
|
item.edits.push_back(edit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.snippet = insert_text_format == 2;
|
||||||
|
if (item_json.contains("insertTextFormat"))
|
||||||
|
item.snippet = item_json["insertTextFormat"].get<int>() == 2;
|
||||||
|
if (item_json.contains("insertTextMode"))
|
||||||
|
item.asis = item_json["insertTextMode"].get<int>() == 1;
|
||||||
|
if (item_json.contains("commitCharacters"))
|
||||||
|
for (auto &c : item_json["commitCharacters"])
|
||||||
|
if (c.is_string() && c.get<std::string>().size() == 1)
|
||||||
|
item.end_chars.push_back(c.get<std::string>()[0]);
|
||||||
|
session.items.push_back(std::move(item));
|
||||||
|
session.visible.push_back(session.items.size() - 1);
|
||||||
|
}
|
||||||
|
session.box.hidden = false;
|
||||||
|
session.box.render_update();
|
||||||
|
};
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, hook.row);
|
||||||
|
uint32_t length;
|
||||||
|
char *line = next_line(it, &length);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t col = utf8_offset_to_utf16(line, length, editor->cursor.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
lock.unlock();
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/completion"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument", {{"uri", editor->uri}}},
|
||||||
|
{"position", {{"line", editor->cursor.row}, {"character", col}}}}}};
|
||||||
|
if (editor->completion.trigger > 0) {
|
||||||
|
json context = {{"triggerKind", editor->completion.trigger}};
|
||||||
|
if (editor->completion.trigger == 2 && editor->completion.trigger_char)
|
||||||
|
context["triggerCharacter"] =
|
||||||
|
std::string(1, *editor->completion.trigger_char);
|
||||||
|
message["params"]["context"] = context;
|
||||||
|
}
|
||||||
|
lsp_send(editor->lsp, message, pending);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_completion(Editor *editor, KeyEvent event) {
|
||||||
|
if (!editor->lsp || !editor->lsp->allow_completion)
|
||||||
|
return;
|
||||||
|
if (mode != INSERT) {
|
||||||
|
editor->completion.active = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::unique_lock lock(editor->completion.mtx);
|
||||||
|
if (event.key_type == KEY_PASTE) {
|
||||||
|
editor->completion.active = false;
|
||||||
|
return;
|
||||||
|
} else if (event.key_type == KEY_CHAR) {
|
||||||
|
char ch = *event.c;
|
||||||
|
if (!editor->completion.active) {
|
||||||
|
for (char c : editor->lsp->trigger_chars)
|
||||||
|
if (c == ch) {
|
||||||
|
editor->completion.trigger = 2;
|
||||||
|
editor->completion.trigger_char = c;
|
||||||
|
completion_request(editor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!editor->completion.items.empty()) {
|
||||||
|
const auto &item = editor->completion.items[editor->completion.select];
|
||||||
|
const std::vector<char> &end_chars =
|
||||||
|
item.end_chars.empty() ? editor->lsp->end_chars : item.end_chars;
|
||||||
|
for (char c : end_chars)
|
||||||
|
if (c == ch) {
|
||||||
|
complete_accept(editor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
|
||||||
|
(ch >= '0' && ch <= '9') || ch == '_') {
|
||||||
|
if (editor->completion.active) {
|
||||||
|
if (editor->completion.complete)
|
||||||
|
completion_filter(editor);
|
||||||
|
else
|
||||||
|
completion_request(editor);
|
||||||
|
} else {
|
||||||
|
editor->completion.trigger = 3;
|
||||||
|
completion_request(editor);
|
||||||
|
}
|
||||||
|
} else if (ch == CTRL('\\')) {
|
||||||
|
if (editor->completion.active && !editor->completion.visible.empty()) {
|
||||||
|
complete_accept(editor);
|
||||||
|
} else {
|
||||||
|
editor->completion.trigger = 1;
|
||||||
|
completion_request(editor);
|
||||||
|
}
|
||||||
|
} else if (ch == CTRL('p')) {
|
||||||
|
if (editor->completion.active)
|
||||||
|
complete_next(editor);
|
||||||
|
} else if (ch == CTRL('o')) {
|
||||||
|
if (editor->completion.active)
|
||||||
|
complete_prev(editor);
|
||||||
|
} else if (ch == 0x7F || ch == 0x08 || ch == CTRL('W')) {
|
||||||
|
if (editor->completion.active) {
|
||||||
|
if (editor->completion.complete) {
|
||||||
|
if (editor->cursor <= editor->completion.hook)
|
||||||
|
editor->completion.active = false;
|
||||||
|
else
|
||||||
|
completion_filter(editor);
|
||||||
|
} else {
|
||||||
|
if (editor->cursor <= editor->completion.hook)
|
||||||
|
editor->completion.active = false;
|
||||||
|
else
|
||||||
|
completion_request(editor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
editor->completion.active = false;
|
||||||
|
}
|
||||||
|
} else if (event.key_type == KEY_MOUSE && event.mouse_modifier == 0) {
|
||||||
|
// Prolly remove mouse support here
|
||||||
|
// auto &box = editor->completion.box;
|
||||||
|
// if (event.mouse_y >= box.position.row &&
|
||||||
|
// event.mouse_x >= box.position.col) {
|
||||||
|
// uint32_t row = event.mouse_y - box.position.row;
|
||||||
|
// uint32_t col = event.mouse_x - box.position.col;
|
||||||
|
// if (row < box.size.row && col < box.size.col) {
|
||||||
|
// uint8_t idx = 0;
|
||||||
|
// /* TODO: fix index relative to scroll */
|
||||||
|
// complete_select(editor, idx);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if it is being implemented then stop main event handler from processing
|
||||||
|
// when click inside the box
|
||||||
|
editor->completion.active = false;
|
||||||
|
} else {
|
||||||
|
editor->completion.active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void completion_resolve_doc(Editor *editor) {
|
||||||
|
auto &item = editor->completion.items[editor->completion.select];
|
||||||
|
if (item.documentation)
|
||||||
|
return;
|
||||||
|
item.documentation = "";
|
||||||
|
LSPPending *pending = new LSPPending();
|
||||||
|
pending->editor = editor;
|
||||||
|
pending->method = "completionItem/resolve";
|
||||||
|
pending->callback = [](Editor *editor, std::string, json message) {
|
||||||
|
std::unique_lock lock(editor->completion.mtx);
|
||||||
|
auto &item = editor->completion.items[editor->completion.select];
|
||||||
|
if (message["result"].contains("documentation")) {
|
||||||
|
if (message["result"]["documentation"].is_string()) {
|
||||||
|
item.documentation =
|
||||||
|
message["result"]["documentation"].get<std::string>();
|
||||||
|
} else if (message["result"]["documentation"].contains("value") &&
|
||||||
|
message["result"]["documentation"]["value"].is_string()) {
|
||||||
|
item.is_markup =
|
||||||
|
message["result"]["documentation"]["kind"].get<std::string>() ==
|
||||||
|
"markdown";
|
||||||
|
std::string documentation =
|
||||||
|
message["result"]["documentation"]["value"].get<std::string>();
|
||||||
|
if (documentation.size() > 1024)
|
||||||
|
item.is_markup = false;
|
||||||
|
if (item.is_markup) {
|
||||||
|
item.documentation =
|
||||||
|
substitute_fence(documentation, editor->lang.name);
|
||||||
|
} else {
|
||||||
|
item.documentation = documentation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editor->completion.box.render_update();
|
||||||
|
};
|
||||||
|
json message = {{"jsonrpc", "2.0"},
|
||||||
|
{"method", "completionItem/resolve"},
|
||||||
|
{"params", item.original}};
|
||||||
|
lsp_send(editor->lsp, message, pending);
|
||||||
|
}
|
||||||
|
|
||||||
|
void complete_accept(Editor *editor) {
|
||||||
|
if (!editor->completion.active || editor->completion.box.hidden)
|
||||||
|
return;
|
||||||
|
auto &item = editor->completion.items[editor->completion.select];
|
||||||
|
// TODO: support snippets and asis here
|
||||||
|
// once indentation engine is implemented
|
||||||
|
if (editor->completion.version != editor->lsp_version) {
|
||||||
|
int delta_col = 0;
|
||||||
|
TextEdit &e = item.edits[0];
|
||||||
|
if (e.end.row == editor->cursor.row) {
|
||||||
|
delta_col = editor->cursor.col - e.end.col;
|
||||||
|
e.end.col = editor->cursor.col;
|
||||||
|
for (size_t i = 1; i < item.edits.size(); ++i) {
|
||||||
|
TextEdit &e = item.edits[i];
|
||||||
|
if (e.start.row == editor->cursor.row) {
|
||||||
|
e.start.col += delta_col;
|
||||||
|
if (e.end.row == editor->cursor.row)
|
||||||
|
e.end.col += delta_col;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apply_lsp_edits(editor, item.edits, true);
|
||||||
|
editor->completion.active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static int visible_index(const CompletionSession &s) {
|
||||||
|
for (size_t i = 0; i < s.visible.size(); ++i)
|
||||||
|
if (s.visible[i] == s.select)
|
||||||
|
return (int)i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void complete_next(Editor *editor) {
|
||||||
|
auto &s = editor->completion;
|
||||||
|
if (!s.active || s.box.hidden || s.visible.empty())
|
||||||
|
return;
|
||||||
|
int vi = visible_index(s);
|
||||||
|
if (vi < 0)
|
||||||
|
vi = 0;
|
||||||
|
else
|
||||||
|
vi = (vi + 1) % s.visible.size();
|
||||||
|
s.select = s.visible[vi];
|
||||||
|
completion_resolve_doc(editor);
|
||||||
|
completion_adjust_scroll(editor->completion);
|
||||||
|
editor->completion.box.render_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void complete_prev(Editor *editor) {
|
||||||
|
auto &s = editor->completion;
|
||||||
|
if (!s.active || s.box.hidden || s.visible.empty())
|
||||||
|
return;
|
||||||
|
int vi = visible_index(s);
|
||||||
|
if (vi < 0)
|
||||||
|
vi = 0;
|
||||||
|
else
|
||||||
|
vi = (vi + s.visible.size() - 1) % s.visible.size();
|
||||||
|
s.select = s.visible[vi];
|
||||||
|
completion_resolve_doc(editor);
|
||||||
|
completion_adjust_scroll(editor->completion);
|
||||||
|
editor->completion.box.render_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void complete_select(Editor *editor, uint8_t index) {
|
||||||
|
editor->completion.select = index;
|
||||||
|
complete_accept(editor);
|
||||||
|
}
|
||||||
192
src/editor/cursor.cc
Normal file
192
src/editor/cursor.cc
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
Coord move_right(Editor *editor, Coord cursor, uint32_t number) {
|
||||||
|
Coord result = cursor;
|
||||||
|
if (!editor || !editor->root || number == 0)
|
||||||
|
return result;
|
||||||
|
uint32_t row = result.row;
|
||||||
|
uint32_t col = result.col;
|
||||||
|
uint32_t line_len = 0;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, row);
|
||||||
|
if (!it)
|
||||||
|
return result;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
--line_len;
|
||||||
|
while (number > 0) {
|
||||||
|
if (col >= line_len) {
|
||||||
|
uint32_t next_row = row + 1;
|
||||||
|
if (next_row >= editor->root->line_count) {
|
||||||
|
col = line_len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
row = next_row;
|
||||||
|
col = 0;
|
||||||
|
line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
--line_len;
|
||||||
|
} else {
|
||||||
|
uint32_t inc =
|
||||||
|
grapheme_next_character_break_utf8(line + col, line_len - col);
|
||||||
|
if (inc == 0)
|
||||||
|
break;
|
||||||
|
col += inc;
|
||||||
|
}
|
||||||
|
number--;
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
result.row = row;
|
||||||
|
result.col = col;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Coord move_left(Editor *editor, Coord cursor, uint32_t number) {
|
||||||
|
Coord result = cursor;
|
||||||
|
if (!editor || !editor->root || number == 0)
|
||||||
|
return result;
|
||||||
|
uint32_t row = result.row;
|
||||||
|
uint32_t col = result.col;
|
||||||
|
uint32_t len = 0;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, row);
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
bool iterator_ahead = true;
|
||||||
|
while (number > 0) {
|
||||||
|
if (col == 0) {
|
||||||
|
if (row == 0)
|
||||||
|
break;
|
||||||
|
if (iterator_ahead) {
|
||||||
|
prev_line(it, nullptr);
|
||||||
|
iterator_ahead = false;
|
||||||
|
}
|
||||||
|
line = nullptr;
|
||||||
|
row--;
|
||||||
|
line = prev_line(it, &len);
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
col = len;
|
||||||
|
} else {
|
||||||
|
uint32_t new_col = 0;
|
||||||
|
while (new_col < col) {
|
||||||
|
uint32_t inc =
|
||||||
|
grapheme_next_character_break_utf8(line + new_col, len - new_col);
|
||||||
|
if (new_col + inc >= col)
|
||||||
|
break;
|
||||||
|
new_col += inc;
|
||||||
|
}
|
||||||
|
col = new_col;
|
||||||
|
}
|
||||||
|
number--;
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
result.row = row;
|
||||||
|
result.col = col;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cursor_down(Editor *editor, uint32_t number) {
|
||||||
|
if (!editor || !editor->root || number == 0)
|
||||||
|
return;
|
||||||
|
uint32_t visual_col = editor->cursor_preffered;
|
||||||
|
if (visual_col == UINT32_MAX) {
|
||||||
|
uint32_t len;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editor->cursor_preffered =
|
||||||
|
get_visual_col_from_bytes(line, len, editor->cursor.col);
|
||||||
|
visual_col = editor->cursor_preffered;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
editor->cursor.row =
|
||||||
|
MIN(editor->cursor.row + number, editor->root->line_count - 1);
|
||||||
|
uint32_t len;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
editor->cursor.col = get_bytes_from_visual_col(line, len, visual_col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cursor_up(Editor *editor, uint32_t number) {
|
||||||
|
if (!editor || !editor->root || number == 0 || editor->cursor.row == 0)
|
||||||
|
return;
|
||||||
|
uint32_t len;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
char *line_content = next_line(it, &len);
|
||||||
|
if (!line_content)
|
||||||
|
return;
|
||||||
|
if (editor->cursor_preffered == UINT32_MAX)
|
||||||
|
editor->cursor_preffered =
|
||||||
|
get_visual_col_from_bytes(line_content, len, editor->cursor.col);
|
||||||
|
uint32_t visual_col = editor->cursor_preffered;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
uint32_t target_row = editor->cursor.row;
|
||||||
|
while (number > 0 && target_row > 0) {
|
||||||
|
target_row--;
|
||||||
|
if (target_row == 0) {
|
||||||
|
number--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
number--;
|
||||||
|
}
|
||||||
|
it = begin_l_iter(editor->root, target_row);
|
||||||
|
line_content = next_line(it, &len);
|
||||||
|
if (line_content) {
|
||||||
|
if (len > 0 && line_content[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
editor->cursor.row = target_row;
|
||||||
|
editor->cursor.col =
|
||||||
|
get_bytes_from_visual_col(line_content, len, visual_col);
|
||||||
|
} else {
|
||||||
|
editor->cursor.row = 0;
|
||||||
|
editor->cursor.col = 0;
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cursor_right(Editor *editor, uint32_t number) {
|
||||||
|
if (!editor || !editor->root || number == 0)
|
||||||
|
return;
|
||||||
|
editor->cursor = move_right(editor, editor->cursor, number);
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cursor_left(Editor *editor, uint32_t number) {
|
||||||
|
if (!editor || !editor->root || number == 0)
|
||||||
|
return;
|
||||||
|
editor->cursor = move_left(editor, editor->cursor, number);
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
}
|
||||||
280
src/editor/edit.cc
Normal file
280
src/editor/edit.cc
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "lsp/lsp.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
void edit_erase(Editor *editor, Coord pos, int64_t len) {
|
||||||
|
if (len == 0)
|
||||||
|
return;
|
||||||
|
if (len < 0) {
|
||||||
|
std::shared_lock lock_1(editor->knot_mtx);
|
||||||
|
uint32_t cursor_original =
|
||||||
|
line_to_byte(editor->root, editor->cursor.row, nullptr) +
|
||||||
|
editor->cursor.col;
|
||||||
|
uint32_t byte_pos = line_to_byte(editor->root, pos.row, nullptr) + pos.col;
|
||||||
|
Coord point = move_left(editor, pos, -len);
|
||||||
|
json lsp_range;
|
||||||
|
bool do_lsp = (editor->lsp != nullptr);
|
||||||
|
if (do_lsp) {
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, point.row);
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
int utf16_start = 0;
|
||||||
|
if (line)
|
||||||
|
utf16_start = utf8_offset_to_utf16(line, len, point.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
it = begin_l_iter(editor->root, pos.row);
|
||||||
|
line = next_line(it, &len);
|
||||||
|
int utf16_end = 0;
|
||||||
|
if (line)
|
||||||
|
utf16_end = utf8_offset_to_utf16(line, len, pos.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
lsp_range = {{"start", {{"line", point.row}, {"character", utf16_start}}},
|
||||||
|
{"end", {{"line", pos.row}, {"character", utf16_end}}}};
|
||||||
|
}
|
||||||
|
uint32_t start = line_to_byte(editor->root, point.row, nullptr) + point.col;
|
||||||
|
if (cursor_original > start && cursor_original <= byte_pos) {
|
||||||
|
editor->cursor = point;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
} else if (cursor_original > byte_pos) {
|
||||||
|
uint32_t cursor_new = cursor_original - (byte_pos - start);
|
||||||
|
uint32_t new_col;
|
||||||
|
uint32_t new_row = byte_to_line(editor->root, cursor_new, &new_col);
|
||||||
|
editor->cursor = {new_row, new_col};
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
}
|
||||||
|
lock_1.unlock();
|
||||||
|
uint32_t start_row = point.row;
|
||||||
|
uint32_t end_row = pos.row;
|
||||||
|
apply_hook_deletion(editor, start_row + 1, end_row);
|
||||||
|
std::unique_lock lock_2(editor->knot_mtx);
|
||||||
|
editor->root = erase(editor->root, start, byte_pos - start);
|
||||||
|
lock_2.unlock();
|
||||||
|
if (editor->parser)
|
||||||
|
editor->parser->edit(start_row, end_row, 0);
|
||||||
|
if (do_lsp) {
|
||||||
|
if (editor->lsp->incremental_sync) {
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didChange"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument",
|
||||||
|
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
|
||||||
|
{"contentChanges",
|
||||||
|
json::array({{{"range", lsp_range}, {"text", ""}}})}}}};
|
||||||
|
lsp_send(editor->lsp, message, nullptr);
|
||||||
|
} else {
|
||||||
|
char *buf = read(editor->root, 0, editor->root->char_count);
|
||||||
|
std::string text(buf);
|
||||||
|
free(buf);
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didChange"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument",
|
||||||
|
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
|
||||||
|
{"contentChanges", json::array({{{"text", text}}})}}}};
|
||||||
|
lsp_send(editor->lsp, message, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::shared_lock lock_1(editor->knot_mtx);
|
||||||
|
uint32_t cursor_original =
|
||||||
|
line_to_byte(editor->root, editor->cursor.row, nullptr) +
|
||||||
|
editor->cursor.col;
|
||||||
|
uint32_t byte_pos = line_to_byte(editor->root, pos.row, nullptr) + pos.col;
|
||||||
|
Coord point = move_right(editor, pos, len);
|
||||||
|
json lsp_range;
|
||||||
|
bool do_lsp = (editor->lsp != nullptr);
|
||||||
|
if (do_lsp) {
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, pos.row);
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
int utf16_start = 0;
|
||||||
|
if (line)
|
||||||
|
utf16_start = utf8_offset_to_utf16(line, line_len, pos.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
it = begin_l_iter(editor->root, point.row);
|
||||||
|
line = next_line(it, &line_len);
|
||||||
|
int utf16_end = 0;
|
||||||
|
if (line)
|
||||||
|
utf16_end = utf8_offset_to_utf16(line, line_len, point.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
lsp_range = {{"start", {{"line", pos.row}, {"character", utf16_start}}},
|
||||||
|
{"end", {{"line", point.row}, {"character", utf16_end}}}};
|
||||||
|
}
|
||||||
|
uint32_t end = line_to_byte(editor->root, point.row, nullptr) + point.col;
|
||||||
|
if (cursor_original > byte_pos && cursor_original <= end) {
|
||||||
|
editor->cursor = pos;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
} else if (cursor_original > end) {
|
||||||
|
uint32_t cursor_new = cursor_original - (end - byte_pos);
|
||||||
|
uint32_t new_col;
|
||||||
|
uint32_t new_row = byte_to_line(editor->root, cursor_new, &new_col);
|
||||||
|
editor->cursor = {new_row, new_col};
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
}
|
||||||
|
lock_1.unlock();
|
||||||
|
uint32_t start_row = pos.row;
|
||||||
|
uint32_t end_row = point.row;
|
||||||
|
apply_hook_deletion(editor, start_row + 1, end_row);
|
||||||
|
std::unique_lock lock_2(editor->knot_mtx);
|
||||||
|
editor->root = erase(editor->root, byte_pos, end - byte_pos);
|
||||||
|
lock_2.unlock();
|
||||||
|
if (editor->parser)
|
||||||
|
editor->parser->edit(start_row, end_row, 0);
|
||||||
|
if (do_lsp) {
|
||||||
|
if (editor->lsp->incremental_sync) {
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didChange"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument",
|
||||||
|
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
|
||||||
|
{"contentChanges",
|
||||||
|
json::array({{{"range", lsp_range}, {"text", ""}}})}}}};
|
||||||
|
lsp_send(editor->lsp, message, nullptr);
|
||||||
|
} else {
|
||||||
|
char *buf = read(editor->root, 0, editor->root->char_count);
|
||||||
|
std::string text(buf);
|
||||||
|
free(buf);
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didChange"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument",
|
||||||
|
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
|
||||||
|
{"contentChanges", json::array({{{"text", text}}})}}}};
|
||||||
|
lsp_send(editor->lsp, message, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void edit_insert(Editor *editor, Coord pos, char *data, uint32_t len) {
|
||||||
|
std::shared_lock lock_1(editor->knot_mtx);
|
||||||
|
uint32_t cursor_original =
|
||||||
|
line_to_byte(editor->root, editor->cursor.row, nullptr) +
|
||||||
|
editor->cursor.col;
|
||||||
|
uint32_t byte_pos = line_to_byte(editor->root, pos.row, nullptr) + pos.col;
|
||||||
|
if (cursor_original > byte_pos) {
|
||||||
|
uint32_t cursor_new = cursor_original + len;
|
||||||
|
uint32_t new_col;
|
||||||
|
uint32_t new_row = byte_to_line(editor->root, cursor_new, &new_col);
|
||||||
|
editor->cursor = {new_row, new_col};
|
||||||
|
}
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, pos.row);
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
int utf16_col = 0;
|
||||||
|
if (line)
|
||||||
|
utf16_col = utf8_offset_to_utf16(line, line_len, pos.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
lock_1.unlock();
|
||||||
|
std::unique_lock lock_2(editor->knot_mtx);
|
||||||
|
editor->root = insert(editor->root, byte_pos, data, len);
|
||||||
|
uint32_t rows = 0;
|
||||||
|
for (uint32_t i = 0; i < len; i++)
|
||||||
|
if (data[i] == '\n')
|
||||||
|
rows++;
|
||||||
|
apply_hook_insertion(editor, pos.row, rows);
|
||||||
|
lock_2.unlock();
|
||||||
|
if (editor->parser)
|
||||||
|
editor->parser->edit(pos.row, pos.row, rows);
|
||||||
|
if (editor->lsp) {
|
||||||
|
if (editor->lsp->incremental_sync) {
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didChange"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument",
|
||||||
|
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
|
||||||
|
{"contentChanges",
|
||||||
|
json::array(
|
||||||
|
{{{"range",
|
||||||
|
{{"start", {{"line", pos.row}, {"character", utf16_col}}},
|
||||||
|
{"end", {{"line", pos.row}, {"character", utf16_col}}}}},
|
||||||
|
{"text", std::string(data, len)}}})}}}};
|
||||||
|
lsp_send(editor->lsp, message, nullptr);
|
||||||
|
} else {
|
||||||
|
char *buf = read(editor->root, 0, editor->root->char_count);
|
||||||
|
std::string text(buf);
|
||||||
|
free(buf);
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didChange"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument",
|
||||||
|
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
|
||||||
|
{"contentChanges", json::array({{{"text", text}}})}}}};
|
||||||
|
lsp_send(editor->lsp, message, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void edit_replace(Editor *editor, Coord start, Coord end, const char *text,
|
||||||
|
uint32_t len) {
|
||||||
|
std::unique_lock lock(editor->knot_mtx);
|
||||||
|
uint32_t start_byte =
|
||||||
|
line_to_byte(editor->root, start.row, nullptr) + start.col;
|
||||||
|
uint32_t end_byte = line_to_byte(editor->root, end.row, nullptr) + end.col;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, start.row);
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
int utf16_start = 0;
|
||||||
|
if (line)
|
||||||
|
utf16_start = utf8_offset_to_utf16(line, line_len, start.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
it = begin_l_iter(editor->root, end.row);
|
||||||
|
line = next_line(it, &line_len);
|
||||||
|
int utf16_end = 0;
|
||||||
|
if (line)
|
||||||
|
utf16_end = utf8_offset_to_utf16(line, line_len, end.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
if (start_byte != end_byte)
|
||||||
|
editor->root = erase(editor->root, start_byte, end_byte - start_byte);
|
||||||
|
if (len > 0)
|
||||||
|
editor->root = insert(editor->root, start_byte, (char *)text, len);
|
||||||
|
uint32_t rows = 0;
|
||||||
|
for (uint32_t i = 0; i < len; i++)
|
||||||
|
if (text[i] == '\n')
|
||||||
|
rows++;
|
||||||
|
if (editor->parser)
|
||||||
|
editor->parser->edit(start.row, end.row - 1, rows);
|
||||||
|
if (editor->lsp) {
|
||||||
|
if (editor->lsp->incremental_sync) {
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didChange"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument",
|
||||||
|
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
|
||||||
|
{"contentChanges",
|
||||||
|
json::array(
|
||||||
|
{{{"range",
|
||||||
|
{{"start",
|
||||||
|
{{"line", start.row}, {"character", utf16_start}}},
|
||||||
|
{"end", {{"line", end.row}, {"character", utf16_end}}}}},
|
||||||
|
{"text", std::string(text, len)}}})}}}};
|
||||||
|
lsp_send(editor->lsp, message, nullptr);
|
||||||
|
} else {
|
||||||
|
char *buf = read(editor->root, 0, editor->root->char_count);
|
||||||
|
std::string full_text(buf);
|
||||||
|
free(buf);
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didChange"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument",
|
||||||
|
{{"uri", editor->uri}, {"version", ++editor->lsp_version}}},
|
||||||
|
{"contentChanges", json::array({{{"text", full_text}}})}}}};
|
||||||
|
lsp_send(editor->lsp, message, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
145
src/editor/editor.cc
Normal file
145
src/editor/editor.cc
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "editor/decl.h"
|
||||||
|
#include "lsp/lsp.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "syntax/langs.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
Editor *new_editor(const char *filename_arg, Coord position, Coord size,
|
||||||
|
uint8_t eol) {
|
||||||
|
Editor *editor = new Editor();
|
||||||
|
if (!editor)
|
||||||
|
return nullptr;
|
||||||
|
uint32_t len = 0;
|
||||||
|
std::string filename = path_abs(filename_arg);
|
||||||
|
editor->unix_eol = eol & 1;
|
||||||
|
char *str = load_file(filename.c_str(), &len, &editor->unix_eol);
|
||||||
|
if (!str) {
|
||||||
|
str = (char *)malloc(1);
|
||||||
|
*str = '\n';
|
||||||
|
len = 1;
|
||||||
|
}
|
||||||
|
if ((eol >> 1) & 1)
|
||||||
|
editor->unix_eol = eol & 1;
|
||||||
|
editor->filename = filename;
|
||||||
|
editor->uri = path_to_file_uri(filename);
|
||||||
|
editor->position = position;
|
||||||
|
editor->size = size;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
if (len == 0) {
|
||||||
|
free(str);
|
||||||
|
str = (char *)malloc(1);
|
||||||
|
*str = '\n';
|
||||||
|
len = 1;
|
||||||
|
}
|
||||||
|
editor->root = load(str, len, optimal_chunk_size(len));
|
||||||
|
free(str);
|
||||||
|
editor->lang = language_for_file(filename.c_str());
|
||||||
|
if (parsers.find(editor->lang.name) != parsers.end())
|
||||||
|
editor->parser = new Parser(editor, editor->lang.name, size.row + 5);
|
||||||
|
if (editor->lang.name == "css" || editor->lang.name == "html" ||
|
||||||
|
editor->lang.name == "javascript" || editor->lang.name == "markdown" ||
|
||||||
|
editor->lang.name == "typescript")
|
||||||
|
editor->is_css_color = true;
|
||||||
|
if (len <= (1024 * 28))
|
||||||
|
request_add_to_lsp(editor->lang, editor);
|
||||||
|
editor->indents.compute_indent(editor);
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_editor(Editor *editor) {
|
||||||
|
remove_from_lsp(editor);
|
||||||
|
if (editor->parser)
|
||||||
|
delete editor->parser;
|
||||||
|
editor->parser = nullptr;
|
||||||
|
free_rope(editor->root);
|
||||||
|
delete editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void save_file(Editor *editor) {
|
||||||
|
if (!editor || !editor->root)
|
||||||
|
return;
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
int version = editor->lsp_version;
|
||||||
|
uint32_t char_count = editor->root->char_count;
|
||||||
|
char *str = read(editor->root, 0, char_count);
|
||||||
|
if (!str)
|
||||||
|
return;
|
||||||
|
lock.unlock();
|
||||||
|
std::ofstream out(editor->filename);
|
||||||
|
if (!editor->unix_eol) {
|
||||||
|
for (uint32_t i = 0; i < char_count; ++i) {
|
||||||
|
if (str[i] == '\n')
|
||||||
|
out.put('\r');
|
||||||
|
out.put(str[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.write(str, char_count);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
free(str);
|
||||||
|
bar.log("Written " + std::to_string(char_count) + " bytes to " +
|
||||||
|
editor->filename);
|
||||||
|
if (editor->lsp) {
|
||||||
|
json save_msg = {{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/didSave"},
|
||||||
|
{"params", {{"textDocument", {{"uri", editor->uri}}}}}};
|
||||||
|
lsp_send(editor->lsp, save_msg, nullptr);
|
||||||
|
if (editor->lsp->allow_formatting) {
|
||||||
|
json msg = {{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/formatting"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument", {{"uri", editor->uri}}},
|
||||||
|
{"options",
|
||||||
|
{{"tabSize", 2},
|
||||||
|
{"insertSpaces", true},
|
||||||
|
{"trimTrailingWhitespace", true},
|
||||||
|
{"trimFinalNewlines", true}}}}}};
|
||||||
|
LSPPending *pending = new LSPPending();
|
||||||
|
pending->editor = editor;
|
||||||
|
pending->method = "textDocument/formatting";
|
||||||
|
pending->callback = [save_msg, version](Editor *editor, std::string,
|
||||||
|
json message) {
|
||||||
|
if (version != editor->lsp_version)
|
||||||
|
return;
|
||||||
|
auto &edits = message["result"];
|
||||||
|
if (edits.is_array()) {
|
||||||
|
std::vector<TextEdit> t_edits;
|
||||||
|
t_edits.reserve(edits.size());
|
||||||
|
for (auto &edit : edits) {
|
||||||
|
TextEdit t_edit;
|
||||||
|
t_edit.text = edit.value("newText", "");
|
||||||
|
t_edit.start.row = edit["range"]["start"]["line"];
|
||||||
|
t_edit.start.col = edit["range"]["start"]["character"];
|
||||||
|
t_edit.end.row = edit["range"]["end"]["line"];
|
||||||
|
t_edit.end.col = edit["range"]["end"]["character"];
|
||||||
|
utf8_normalize_edit(editor, &t_edit);
|
||||||
|
t_edits.push_back(t_edit);
|
||||||
|
}
|
||||||
|
apply_lsp_edits(editor, t_edits, false);
|
||||||
|
ensure_scroll(editor);
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
uint32_t char_count = editor->root->char_count;
|
||||||
|
char *str = read(editor->root, 0, char_count);
|
||||||
|
if (!str)
|
||||||
|
return;
|
||||||
|
lock.unlock();
|
||||||
|
std::ofstream out(editor->filename);
|
||||||
|
if (!editor->unix_eol) {
|
||||||
|
for (uint32_t i = 0; i < char_count; ++i) {
|
||||||
|
if (str[i] == '\n')
|
||||||
|
out.put('\r');
|
||||||
|
out.put(str[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out.write(str, char_count);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
free(str);
|
||||||
|
lsp_send(editor->lsp, save_msg, nullptr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lsp_send(editor->lsp, msg, pending);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
235
src/editor/events.cc
Normal file
235
src/editor/events.cc
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "editor/helpers.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
void handle_editor_event(Editor *editor, KeyEvent event) {
|
||||||
|
uint8_t old_mode = mode;
|
||||||
|
if (editor->hover_active)
|
||||||
|
editor->hover_active = false;
|
||||||
|
handle_mouse(editor, event);
|
||||||
|
if (event.key_type == KEY_SPECIAL) {
|
||||||
|
switch (event.special_modifier) {
|
||||||
|
case 0:
|
||||||
|
switch (event.special_key) {
|
||||||
|
case KEY_DOWN:
|
||||||
|
cursor_down(editor, 1);
|
||||||
|
break;
|
||||||
|
case KEY_UP:
|
||||||
|
cursor_up(editor, 1);
|
||||||
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
cursor_left(editor, 1);
|
||||||
|
break;
|
||||||
|
case KEY_RIGHT:
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CNTRL:
|
||||||
|
switch (event.special_key) {
|
||||||
|
case KEY_DOWN:
|
||||||
|
cursor_down(editor, 5);
|
||||||
|
break;
|
||||||
|
case KEY_UP:
|
||||||
|
cursor_up(editor, 5);
|
||||||
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
cursor_prev_word(editor);
|
||||||
|
case KEY_RIGHT:
|
||||||
|
cursor_next_word(editor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ALT:
|
||||||
|
switch (event.special_key) {
|
||||||
|
case KEY_DOWN:
|
||||||
|
move_line_down(editor);
|
||||||
|
break;
|
||||||
|
case KEY_UP:
|
||||||
|
move_line_up(editor);
|
||||||
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
cursor_left(editor, 8);
|
||||||
|
break;
|
||||||
|
case KEY_RIGHT:
|
||||||
|
cursor_right(editor, 8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (mode) {
|
||||||
|
case NORMAL:
|
||||||
|
if (event.key_type == KEY_CHAR && event.len == 1) {
|
||||||
|
switch (event.c[0]) {
|
||||||
|
case 'u':
|
||||||
|
select_all(editor);
|
||||||
|
break;
|
||||||
|
case CTRL('h'):
|
||||||
|
editor->hover.scroll(-1);
|
||||||
|
editor->hover_active = true;
|
||||||
|
break;
|
||||||
|
case CTRL('l'):
|
||||||
|
editor->hover.scroll(1);
|
||||||
|
editor->hover_active = true;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
fetch_lsp_hover(editor);
|
||||||
|
break;
|
||||||
|
case 'a': {
|
||||||
|
mode = INSERT;
|
||||||
|
Coord start = editor->cursor;
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
if (start.row != editor->cursor.row)
|
||||||
|
cursor_left(editor, 1);
|
||||||
|
} break;
|
||||||
|
case 'i':
|
||||||
|
mode = INSERT;
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
mode = JUMPER;
|
||||||
|
editor->jumper_set = true;
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
mode = JUMPER;
|
||||||
|
editor->jumper_set = false;
|
||||||
|
break;
|
||||||
|
case 'N':
|
||||||
|
clear_hooks_at_line(editor, editor->cursor.row);
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
case 'v':
|
||||||
|
mode = SELECT;
|
||||||
|
editor->selection_active = true;
|
||||||
|
editor->selection = editor->cursor;
|
||||||
|
editor->selection_type = CHAR;
|
||||||
|
break;
|
||||||
|
case ';':
|
||||||
|
case ':':
|
||||||
|
mode = RUNNER;
|
||||||
|
break;
|
||||||
|
case 0x7F:
|
||||||
|
cursor_left(editor, 1);
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
cursor_down(editor, 1);
|
||||||
|
break;
|
||||||
|
case '\\':
|
||||||
|
case '|':
|
||||||
|
cursor_up(editor, 1);
|
||||||
|
break;
|
||||||
|
case CTRL('d'):
|
||||||
|
scroll_down(editor, 1);
|
||||||
|
ensure_cursor(editor);
|
||||||
|
break;
|
||||||
|
case CTRL('u'):
|
||||||
|
scroll_up(editor, 1);
|
||||||
|
ensure_cursor(editor);
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
case '.':
|
||||||
|
indent_current_line(editor);
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
case ',':
|
||||||
|
dedent_current_line(editor);
|
||||||
|
break;
|
||||||
|
case CTRL('s'):
|
||||||
|
save_file(editor);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
paste(editor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case INSERT:
|
||||||
|
if (event.key_type == KEY_CHAR) {
|
||||||
|
if (event.len == 1) {
|
||||||
|
if (event.c[0] == '\t') {
|
||||||
|
edit_insert(editor, editor->cursor, (char *)" ", 2);
|
||||||
|
cursor_right(editor, 2);
|
||||||
|
} else if (event.c[0] == '\n' || event.c[0] == '\r') {
|
||||||
|
editor->indents.insert_new_line(editor->cursor);
|
||||||
|
} else if (event.c[0] == CTRL('W')) {
|
||||||
|
delete_prev_word(editor);
|
||||||
|
} else if (isprint((unsigned char)(event.c[0]))) {
|
||||||
|
insert_char(editor, event.c[0]);
|
||||||
|
} else if (event.c[0] == 0x7F || event.c[0] == 0x08) {
|
||||||
|
backspace_edit(editor);
|
||||||
|
} else if (event.c[0] == 0x1B) {
|
||||||
|
normal_mode(editor);
|
||||||
|
}
|
||||||
|
} else if (event.len > 1) {
|
||||||
|
edit_insert(editor, editor->cursor, event.c, event.len);
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
}
|
||||||
|
} else if (event.key_type == KEY_SPECIAL &&
|
||||||
|
event.special_key == KEY_DELETE) {
|
||||||
|
switch (event.special_modifier) {
|
||||||
|
case 0:
|
||||||
|
edit_erase(editor, editor->cursor, 1);
|
||||||
|
break;
|
||||||
|
case CNTRL:
|
||||||
|
delete_next_word(editor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (event.key_type == KEY_PASTE) {
|
||||||
|
insert_str(editor, event.c, event.len);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SELECT:
|
||||||
|
if (event.key_type == KEY_CHAR && event.len == 1) {
|
||||||
|
switch (event.c[0]) {
|
||||||
|
case 0x1B:
|
||||||
|
case 's':
|
||||||
|
case 'v':
|
||||||
|
editor->selection_active = false;
|
||||||
|
mode = NORMAL;
|
||||||
|
break;
|
||||||
|
case 'y':
|
||||||
|
copy(editor);
|
||||||
|
mode = NORMAL;
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
cut(editor);
|
||||||
|
mode = NORMAL;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
paste(editor);
|
||||||
|
mode = NORMAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case JUMPER:
|
||||||
|
if (event.key_type == KEY_CHAR && event.len == 1 &&
|
||||||
|
(event.c[0] >= '!' && event.c[0] <= '~')) {
|
||||||
|
if (editor->jumper_set) {
|
||||||
|
for (uint8_t i = 0; i < 94; i++)
|
||||||
|
if (editor->hooks[i] == editor->cursor.row + 1) {
|
||||||
|
editor->hooks[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
editor->hooks[event.c[0] - '!'] = editor->cursor.row + 1;
|
||||||
|
} else {
|
||||||
|
uint32_t line = editor->hooks[event.c[0] - '!'] - 1;
|
||||||
|
if (line > 0) {
|
||||||
|
editor->cursor = {line, 0};
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mode = NORMAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (old_mode == mode || mode != INSERT)
|
||||||
|
handle_completion(editor, event);
|
||||||
|
ensure_scroll(editor);
|
||||||
|
}
|
||||||
490
src/editor/helpers.cc
Normal file
490
src/editor/helpers.cc
Normal file
@@ -0,0 +1,490 @@
|
|||||||
|
#include "editor/helpers.h"
|
||||||
|
#include "editor/editor.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "lsp/lsp.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
void cut(Editor *editor) {
|
||||||
|
if (mode != SELECT)
|
||||||
|
return;
|
||||||
|
Coord start;
|
||||||
|
uint32_t len;
|
||||||
|
char *text = get_selection(editor, &len, &start);
|
||||||
|
copy_to_clipboard(text, len);
|
||||||
|
len = count_clusters(text, len, 0, len);
|
||||||
|
edit_erase(editor, start, len);
|
||||||
|
free(text);
|
||||||
|
editor->selection_active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void copy(Editor *editor) {
|
||||||
|
if (mode != SELECT)
|
||||||
|
return;
|
||||||
|
uint32_t len;
|
||||||
|
char *text = get_selection(editor, &len, nullptr);
|
||||||
|
copy_to_clipboard(text, len);
|
||||||
|
free(text);
|
||||||
|
editor->selection_active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void paste(Editor *editor) {
|
||||||
|
uint32_t len;
|
||||||
|
if (mode == NORMAL) {
|
||||||
|
char *text = get_from_clipboard(&len);
|
||||||
|
if (text) {
|
||||||
|
insert_str(editor, text, len);
|
||||||
|
free(text);
|
||||||
|
}
|
||||||
|
} else if (mode == SELECT) {
|
||||||
|
char *text = get_from_clipboard(&len);
|
||||||
|
if (text) {
|
||||||
|
Coord start, end;
|
||||||
|
selection_bounds(editor, &start, &end);
|
||||||
|
uint32_t start_byte =
|
||||||
|
line_to_byte(editor->root, start.row, nullptr) + start.col;
|
||||||
|
uint32_t end_byte =
|
||||||
|
line_to_byte(editor->root, end.row, nullptr) + end.col;
|
||||||
|
edit_erase(editor, start, end_byte - start_byte);
|
||||||
|
edit_insert(editor, editor->cursor, text, len);
|
||||||
|
free(text);
|
||||||
|
}
|
||||||
|
editor->selection_active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert_str(Editor *editor, char *c, uint32_t len) {
|
||||||
|
if (c) {
|
||||||
|
edit_insert(editor, editor->cursor, c, len);
|
||||||
|
uint32_t grapheme_len = count_clusters(c, len, 0, len);
|
||||||
|
cursor_right(editor, grapheme_len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void indent_current_line(Editor *editor) {
|
||||||
|
Coord start = editor->cursor;
|
||||||
|
uint32_t delta = editor->indents.indent_line(editor->cursor.row);
|
||||||
|
editor->cursor.col = start.col + delta;
|
||||||
|
editor->cursor.row = start.row;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dedent_current_line(Editor *editor) {
|
||||||
|
Coord start = editor->cursor;
|
||||||
|
uint32_t delta = editor->indents.dedent_line(editor->cursor.row);
|
||||||
|
editor->cursor.col = MAX((int64_t)start.col - delta, 0);
|
||||||
|
editor->cursor.row = start.row;
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert_char(Editor *editor, char c) {
|
||||||
|
uint32_t col = editor->cursor.col;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool skip_insert = false;
|
||||||
|
if (line && col < len) {
|
||||||
|
char next = line[col];
|
||||||
|
if ((c == '}' && next == '}') || (c == ')' && next == ')') ||
|
||||||
|
(c == ']' && next == ']') || (c == '"' && next == '"') ||
|
||||||
|
(c == '\'' && next == '\'')) {
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
skip_insert = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
if (!skip_insert) {
|
||||||
|
char closing = 0;
|
||||||
|
switch (c) {
|
||||||
|
case '{':
|
||||||
|
closing = '}';
|
||||||
|
break;
|
||||||
|
case '(':
|
||||||
|
closing = ')';
|
||||||
|
break;
|
||||||
|
case '[':
|
||||||
|
closing = ']';
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
closing = '"';
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
closing = '\'';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (closing) {
|
||||||
|
char pair[2] = {c, closing};
|
||||||
|
edit_insert(editor, editor->cursor, pair, 2);
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
} else {
|
||||||
|
edit_insert(editor, editor->cursor, &c, 1);
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
}
|
||||||
|
if (editor->lsp && editor->lsp->allow_formatting_on_type) {
|
||||||
|
for (char ch : editor->lsp->format_chars) {
|
||||||
|
if (ch == c) {
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t col = utf8_offset_to_utf16(line, len, editor->cursor.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
int version = editor->lsp_version;
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/onTypeFormatting"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument", {{"uri", editor->uri}}},
|
||||||
|
{"position",
|
||||||
|
{{"line", editor->cursor.row}, {"character", col}}},
|
||||||
|
{"ch", std::string(1, c)},
|
||||||
|
{"options",
|
||||||
|
{{"tabSize", 2},
|
||||||
|
{"insertSpaces", true},
|
||||||
|
{"trimTrailingWhitespace", true},
|
||||||
|
{"trimFinalNewlines", true}}}}}};
|
||||||
|
LSPPending *pending = new LSPPending();
|
||||||
|
pending->editor = editor;
|
||||||
|
pending->method = "textDocument/onTypeFormatting";
|
||||||
|
pending->callback = [version](Editor *editor, std::string,
|
||||||
|
json message) {
|
||||||
|
if (version != editor->lsp_version)
|
||||||
|
return;
|
||||||
|
auto &edits = message["result"];
|
||||||
|
if (edits.is_array()) {
|
||||||
|
std::vector<TextEdit> t_edits;
|
||||||
|
t_edits.reserve(edits.size());
|
||||||
|
for (auto &edit : edits) {
|
||||||
|
TextEdit t_edit;
|
||||||
|
t_edit.text = edit.value("newText", "");
|
||||||
|
t_edit.start.row = edit["range"]["start"]["line"];
|
||||||
|
t_edit.start.col = edit["range"]["start"]["character"];
|
||||||
|
t_edit.end.row = edit["range"]["end"]["line"];
|
||||||
|
t_edit.end.col = edit["range"]["end"]["character"];
|
||||||
|
utf8_normalize_edit(editor, &t_edit);
|
||||||
|
t_edits.push_back(t_edit);
|
||||||
|
}
|
||||||
|
apply_lsp_edits(editor, t_edits, false);
|
||||||
|
ensure_scroll(editor);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lsp_send(editor->lsp, message, pending);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void normal_mode(Editor *editor) {
|
||||||
|
Coord prev_pos = editor->cursor;
|
||||||
|
mode = NORMAL;
|
||||||
|
cursor_left(editor, 1);
|
||||||
|
if (prev_pos.row != editor->cursor.row)
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void backspace_edit(Editor *editor) {
|
||||||
|
Coord prev_pos = editor->cursor;
|
||||||
|
if (prev_pos.col > 0)
|
||||||
|
prev_pos.col--;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
char *line = next_line(it, nullptr);
|
||||||
|
char prev_char = line[prev_pos.col];
|
||||||
|
char next_char = line[editor->cursor.col];
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
bool is_pair = (prev_char == '{' && next_char == '}') ||
|
||||||
|
(prev_char == '(' && next_char == ')') ||
|
||||||
|
(prev_char == '[' && next_char == ']') ||
|
||||||
|
(prev_char == '"' && next_char == '"') ||
|
||||||
|
(prev_char == '\'' && next_char == '\'');
|
||||||
|
if (is_pair) {
|
||||||
|
edit_erase(editor, editor->cursor, 1);
|
||||||
|
edit_erase(editor, prev_pos, 1);
|
||||||
|
} else {
|
||||||
|
edit_erase(editor, editor->cursor, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete_prev_word(Editor *editor) {
|
||||||
|
uint32_t prev_col_byte, prev_col_cluster;
|
||||||
|
word_boundaries(editor, editor->cursor, &prev_col_byte, nullptr,
|
||||||
|
&prev_col_cluster, nullptr);
|
||||||
|
if (prev_col_byte == editor->cursor.col)
|
||||||
|
edit_erase(editor, editor->cursor, -1);
|
||||||
|
else
|
||||||
|
edit_erase(editor, editor->cursor, -(int64_t)prev_col_cluster);
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete_next_word(Editor *editor) {
|
||||||
|
uint32_t next_col_byte, next_col_cluster;
|
||||||
|
word_boundaries(editor, editor->cursor, nullptr, &next_col_byte, nullptr,
|
||||||
|
&next_col_cluster);
|
||||||
|
if (next_col_byte == editor->cursor.col)
|
||||||
|
edit_erase(editor, editor->cursor, 1);
|
||||||
|
else
|
||||||
|
edit_erase(editor, editor->cursor, next_col_cluster);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_hooks_at_line(Editor *editor, uint32_t line) {
|
||||||
|
for (uint8_t i = 0; i < 94; i++)
|
||||||
|
if (editor->hooks[i] == line + 1) {
|
||||||
|
editor->hooks[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cursor_prev_word(Editor *editor) {
|
||||||
|
uint32_t prev_col;
|
||||||
|
word_boundaries(editor, editor->cursor, &prev_col, nullptr, nullptr, nullptr);
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
if (prev_col == editor->cursor.col)
|
||||||
|
cursor_left(editor, 1);
|
||||||
|
else
|
||||||
|
editor->cursor = {editor->cursor.row, prev_col};
|
||||||
|
}
|
||||||
|
|
||||||
|
void cursor_next_word(Editor *editor) {
|
||||||
|
uint32_t next_col;
|
||||||
|
word_boundaries(editor, editor->cursor, nullptr, &next_col, nullptr, nullptr);
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
if (next_col == editor->cursor.col)
|
||||||
|
cursor_right(editor, 1);
|
||||||
|
else
|
||||||
|
editor->cursor = {editor->cursor.row, next_col};
|
||||||
|
}
|
||||||
|
|
||||||
|
void select_all(Editor *editor) {
|
||||||
|
if (editor->root->line_count > 0) {
|
||||||
|
editor->cursor.row = editor->root->line_count - 1;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
return;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
line_len = count_clusters(line, line_len, 0, line_len);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
editor->cursor.col = line_len;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
mode = SELECT;
|
||||||
|
editor->selection_active = true;
|
||||||
|
editor->selection = {0, 0};
|
||||||
|
editor->selection_type = LINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fetch_lsp_hover(Editor *editor) {
|
||||||
|
if (editor->lsp && editor->lsp->allow_hover) {
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t col = utf8_offset_to_utf16(line, line_len, editor->cursor.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
json hover_request = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/hover"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument", {{"uri", editor->uri}}},
|
||||||
|
{"position", {{"line", editor->cursor.row}, {"character", col}}}}}};
|
||||||
|
LSPPending *pending = new LSPPending();
|
||||||
|
pending->editor = editor;
|
||||||
|
pending->method = "textDocument/hover";
|
||||||
|
pending->callback = [](Editor *editor, std::string, json hover) {
|
||||||
|
if (hover.contains("result") && !hover["result"].is_null()) {
|
||||||
|
auto &contents = hover["result"]["contents"];
|
||||||
|
std::string hover_text = "";
|
||||||
|
bool is_markup = false;
|
||||||
|
if (contents.is_object()) {
|
||||||
|
hover_text += contents["value"].get<std::string>();
|
||||||
|
is_markup = (contents["kind"].get<std::string>() == "markdown");
|
||||||
|
} else if (contents.is_array()) {
|
||||||
|
for (auto &block : contents) {
|
||||||
|
if (block.is_string()) {
|
||||||
|
hover_text += block.get<std::string>() + "\n";
|
||||||
|
} else if (block.is_object() && block.contains("language") &&
|
||||||
|
block.contains("value")) {
|
||||||
|
std::string lang = block["language"].get<std::string>();
|
||||||
|
std::string val = block["value"].get<std::string>();
|
||||||
|
is_markup = true;
|
||||||
|
hover_text += "```" + lang + "\n" + val + "\n```\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (contents.is_string()) {
|
||||||
|
hover_text += contents.get<std::string>();
|
||||||
|
}
|
||||||
|
if (!hover_text.empty()) {
|
||||||
|
editor->hover.clear();
|
||||||
|
editor->hover.text = clean_text(hover_text);
|
||||||
|
editor->hover.is_markup = is_markup;
|
||||||
|
editor->hover.render_first();
|
||||||
|
editor->hover_active = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lsp_send(editor->lsp, hover_request, pending);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handle_mouse(Editor *editor, KeyEvent event) {
|
||||||
|
static std::chrono::steady_clock::time_point last_click_time =
|
||||||
|
std::chrono::steady_clock::now();
|
||||||
|
static uint32_t click_count = 0;
|
||||||
|
static Coord last_click_pos = {UINT32_MAX, UINT32_MAX};
|
||||||
|
if (event.key_type == KEY_MOUSE) {
|
||||||
|
auto now = std::chrono::steady_clock::now();
|
||||||
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
now - last_click_time)
|
||||||
|
.count();
|
||||||
|
switch (event.mouse_state) {
|
||||||
|
case SCROLL:
|
||||||
|
switch (event.mouse_direction) {
|
||||||
|
case SCROLL_UP:
|
||||||
|
scroll_up(editor, 4);
|
||||||
|
ensure_cursor(editor);
|
||||||
|
break;
|
||||||
|
case SCROLL_DOWN:
|
||||||
|
scroll_down(editor, 4);
|
||||||
|
ensure_cursor(editor);
|
||||||
|
break;
|
||||||
|
case SCROLL_LEFT:
|
||||||
|
cursor_left(editor, 10);
|
||||||
|
break;
|
||||||
|
case SCROLL_RIGHT:
|
||||||
|
cursor_right(editor, 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PRESS:
|
||||||
|
if (event.mouse_button == LEFT_BTN) {
|
||||||
|
Coord cur_pos = {event.mouse_x, event.mouse_y};
|
||||||
|
if (duration < 250 && last_click_pos == cur_pos)
|
||||||
|
click_count++;
|
||||||
|
else
|
||||||
|
click_count = 1;
|
||||||
|
last_click_time = now;
|
||||||
|
last_click_pos = cur_pos;
|
||||||
|
Coord p = editor_hit_test(editor, event.mouse_x, event.mouse_y);
|
||||||
|
if (p.row == UINT32_MAX && p.col == UINT32_MAX)
|
||||||
|
return;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
if (click_count == 1) {
|
||||||
|
editor->cursor = p;
|
||||||
|
editor->selection = p;
|
||||||
|
if (mode == SELECT) {
|
||||||
|
mode = NORMAL;
|
||||||
|
editor->selection_active = false;
|
||||||
|
}
|
||||||
|
} else if (click_count == 2) {
|
||||||
|
uint32_t prev_col, next_col;
|
||||||
|
word_boundaries(editor, editor->cursor, &prev_col, &next_col, nullptr,
|
||||||
|
nullptr);
|
||||||
|
if (editor->cursor < editor->selection)
|
||||||
|
editor->cursor = {editor->cursor.row, prev_col};
|
||||||
|
else
|
||||||
|
editor->cursor = {editor->cursor.row, next_col};
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
editor->selection_type = WORD;
|
||||||
|
mode = SELECT;
|
||||||
|
editor->selection_active = true;
|
||||||
|
} else if (click_count >= 3) {
|
||||||
|
if (editor->cursor < editor->selection) {
|
||||||
|
editor->cursor = {p.row, 0};
|
||||||
|
} else {
|
||||||
|
uint32_t line_len;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, p.row);
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
return;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
editor->cursor = {p.row, line_len};
|
||||||
|
}
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
editor->selection_type = LINE;
|
||||||
|
mode = SELECT;
|
||||||
|
editor->selection_active = true;
|
||||||
|
click_count = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DRAG:
|
||||||
|
if (event.mouse_button == LEFT_BTN) {
|
||||||
|
Coord p = editor_hit_test(editor, event.mouse_x, event.mouse_y);
|
||||||
|
if (p.row == UINT32_MAX && p.col == UINT32_MAX)
|
||||||
|
return;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
mode = SELECT;
|
||||||
|
if (!editor->selection_active) {
|
||||||
|
editor->selection_active = true;
|
||||||
|
editor->selection_type = CHAR;
|
||||||
|
}
|
||||||
|
uint32_t prev_col, next_col, line_len;
|
||||||
|
switch (editor->selection_type) {
|
||||||
|
case CHAR:
|
||||||
|
editor->cursor = p;
|
||||||
|
break;
|
||||||
|
case WORD:
|
||||||
|
word_boundaries(editor, p, &prev_col, &next_col, nullptr, nullptr);
|
||||||
|
if (editor->cursor < editor->selection)
|
||||||
|
editor->cursor = {p.row, prev_col};
|
||||||
|
else
|
||||||
|
editor->cursor = {p.row, next_col};
|
||||||
|
break;
|
||||||
|
case LINE:
|
||||||
|
if (editor->cursor < editor->selection) {
|
||||||
|
editor->cursor = {p.row, 0};
|
||||||
|
} else {
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, p.row);
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
return;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
editor->cursor = {p.row, line_len};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELEASE:
|
||||||
|
if (event.mouse_button == LEFT_BTN)
|
||||||
|
if (editor->cursor.row == editor->selection.row &&
|
||||||
|
editor->cursor.col == editor->selection.col) {
|
||||||
|
mode = NORMAL;
|
||||||
|
editor->selection_active = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
377
src/editor/indents.cc
Normal file
377
src/editor/indents.cc
Normal file
@@ -0,0 +1,377 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "io/knot.h"
|
||||||
|
#include "lsp/lsp.h"
|
||||||
|
|
||||||
|
void IndentationEngine::compute_indent(Editor *n_editor) {
|
||||||
|
editor = n_editor;
|
||||||
|
uint32_t line_idx = 0;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, 0);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
auto is_set = kLangtoIndent.find(editor->lang.name);
|
||||||
|
indent = is_set != kLangtoIndent.end() ? is_set->second : 0;
|
||||||
|
while (indent == 0 && line_idx < 64) {
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
line_idx++;
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
if (len == 0)
|
||||||
|
continue;
|
||||||
|
if (line[0] == '\t') {
|
||||||
|
indent = 1;
|
||||||
|
} else if (line[0] == ' ') {
|
||||||
|
for (uint32_t i = 0; i < len; i++) {
|
||||||
|
if (line[i] == ' ') {
|
||||||
|
indent += 1;
|
||||||
|
} else {
|
||||||
|
if (indent == 1)
|
||||||
|
indent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (indent == 0)
|
||||||
|
indent = 2;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t IndentationEngine::indent_real(char *line, uint32_t len) {
|
||||||
|
uint32_t spaces = 0;
|
||||||
|
uint32_t tabs = 0;
|
||||||
|
for (uint32_t i = 0; i < len; i++) {
|
||||||
|
if (line[i] == ' ') {
|
||||||
|
spaces += 1;
|
||||||
|
} else if (line[i] == '\t') {
|
||||||
|
tabs += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tabs ? tabs : spaces / indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t IndentationEngine::indent_expected(uint32_t row) {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
uint32_t line_idx = row;
|
||||||
|
if (row == 0)
|
||||||
|
return 0;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, row - 1);
|
||||||
|
if (!it)
|
||||||
|
return 0;
|
||||||
|
next_line(it, nullptr);
|
||||||
|
uint32_t c_indent = 0;
|
||||||
|
while (line_idx--) {
|
||||||
|
uint32_t len;
|
||||||
|
char *line = prev_line(it, &len);
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
if (len == 0)
|
||||||
|
continue;
|
||||||
|
c_indent = indent_real(line, len);
|
||||||
|
auto is_end_set = kLangtoBlockStartsEnd.find(editor->lang.name);
|
||||||
|
auto is_start_set = kLangtoBlockStartsStart.find(editor->lang.name);
|
||||||
|
bool is_end = false;
|
||||||
|
if (is_end_set != kLangtoBlockStartsEnd.end())
|
||||||
|
for (auto end : is_end_set->second)
|
||||||
|
if (ends_with(line, end)) {
|
||||||
|
c_indent++;
|
||||||
|
is_end = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!is_end && is_start_set != kLangtoBlockStartsStart.end())
|
||||||
|
for (auto end : is_start_set->second)
|
||||||
|
if (starts_with(line, end)) {
|
||||||
|
c_indent++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return c_indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t IndentationEngine::set_indent(uint32_t row, int64_t new_indent) {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, row);
|
||||||
|
if (!it)
|
||||||
|
return 0;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
lock.unlock();
|
||||||
|
if (new_indent <= 0)
|
||||||
|
new_indent = 0;
|
||||||
|
uint32_t ws_len = 0;
|
||||||
|
while (ws_len < len && (line[ws_len] == ' ' || line[ws_len] == '\t'))
|
||||||
|
ws_len++;
|
||||||
|
std::string new_ws;
|
||||||
|
if (indent == 1)
|
||||||
|
new_ws.assign(new_indent, '\t');
|
||||||
|
else
|
||||||
|
new_ws.assign(new_indent * indent, ' ');
|
||||||
|
Coord start = {row, 0};
|
||||||
|
Coord end = {row, ws_len};
|
||||||
|
edit_replace(editor, start, end, new_ws.c_str(), new_ws.length());
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return len - ws_len + (new_indent * indent);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t IndentationEngine::indent_line(uint32_t row) {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, row);
|
||||||
|
if (!it)
|
||||||
|
return 0;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
lock.unlock();
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
uint32_t new_indent = indent_real(line, len) + 1;
|
||||||
|
uint32_t ws_len = 0;
|
||||||
|
while (ws_len < len && (line[ws_len] == ' ' || line[ws_len] == '\t'))
|
||||||
|
ws_len++;
|
||||||
|
std::string new_ws;
|
||||||
|
if (indent == 1)
|
||||||
|
new_ws.assign(new_indent, '\t');
|
||||||
|
else
|
||||||
|
new_ws.assign(new_indent * indent, ' ');
|
||||||
|
edit_replace(editor, {row, 0}, {row, ws_len}, new_ws.c_str(),
|
||||||
|
new_indent * indent);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return (uint32_t)ABS((int64_t)ws_len - (new_indent * indent));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t IndentationEngine::dedent_line(uint32_t row) {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, row);
|
||||||
|
if (!it)
|
||||||
|
return 0;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
lock.unlock();
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
int64_t new_indent = (int64_t)indent_real(line, len) - 1;
|
||||||
|
if (new_indent < 0)
|
||||||
|
new_indent = 0;
|
||||||
|
uint32_t ws_len = 0;
|
||||||
|
while (ws_len < len && (line[ws_len] == ' ' || line[ws_len] == '\t'))
|
||||||
|
ws_len++;
|
||||||
|
std::string new_ws;
|
||||||
|
if (indent == 1)
|
||||||
|
new_ws.assign(new_indent, '\t');
|
||||||
|
else
|
||||||
|
new_ws.assign(new_indent * indent, ' ');
|
||||||
|
edit_replace(editor, {row, 0}, {row, ws_len}, new_ws.c_str(),
|
||||||
|
new_indent * indent);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return (uint32_t)ABS((int64_t)ws_len - (new_indent * indent));
|
||||||
|
}
|
||||||
|
|
||||||
|
void IndentationEngine::insert_new_line(Coord cursor) {
|
||||||
|
std::string formatted;
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, cursor.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lock.unlock();
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
if (cursor.col >= len) {
|
||||||
|
auto is_end_full = kLangtoBlockEndsFull.find(editor->lang.name);
|
||||||
|
auto is_end_start = kLangtoBlockEndsStart.find(editor->lang.name);
|
||||||
|
bool end_matched = false;
|
||||||
|
if (is_end_full != kLangtoBlockEndsFull.end())
|
||||||
|
for (auto end : is_end_full->second)
|
||||||
|
if (end == trim(line)) {
|
||||||
|
cursor.col = set_indent(
|
||||||
|
cursor.row, (int64_t)indent_expected(cursor.row) - (int64_t)1);
|
||||||
|
end_matched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!end_matched && is_end_start != kLangtoBlockEndsStart.end())
|
||||||
|
for (auto end : is_end_start->second)
|
||||||
|
if (starts_with(trim(line), end)) {
|
||||||
|
cursor.col =
|
||||||
|
set_indent(cursor.row, (int64_t)indent_expected(cursor.row) - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lock.lock();
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
it = begin_l_iter(editor->root, cursor.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
std::string ending = trim(std::string(line + cursor.col, len - cursor.col));
|
||||||
|
std::string before = trim(std::string(line, cursor.col));
|
||||||
|
uint32_t c_indent = indent_real(line, len);
|
||||||
|
if (!ending.empty()) {
|
||||||
|
bool ending_valid = false;
|
||||||
|
bool starting_valid = false;
|
||||||
|
auto is_end_full = kLangtoBlockEndsFull.find(editor->lang.name);
|
||||||
|
auto is_end_start = kLangtoBlockEndsStart.find(editor->lang.name);
|
||||||
|
auto is_end_set = kLangtoBlockStartsEnd.find(editor->lang.name);
|
||||||
|
auto is_start_set = kLangtoBlockStartsStart.find(editor->lang.name);
|
||||||
|
if (is_end_full != kLangtoBlockEndsFull.end())
|
||||||
|
for (auto end : is_end_full->second)
|
||||||
|
if (ending == end) {
|
||||||
|
ending_valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!ending_valid && is_end_start != kLangtoBlockEndsStart.end())
|
||||||
|
for (auto end : is_end_start->second)
|
||||||
|
if (starts_with(ending, end)) {
|
||||||
|
ending_valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (is_end_set != kLangtoBlockStartsEnd.end())
|
||||||
|
for (auto end : is_end_set->second)
|
||||||
|
if (ends_with(before, end)) {
|
||||||
|
c_indent++;
|
||||||
|
starting_valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!starting_valid && is_start_set != kLangtoBlockStartsStart.end())
|
||||||
|
for (auto end : is_start_set->second)
|
||||||
|
if (starts_with(before, end)) {
|
||||||
|
c_indent++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ending_valid && starting_valid)
|
||||||
|
ending = "\n" +
|
||||||
|
(indent == 1 ? std::string(c_indent, '\t')
|
||||||
|
: std::string(c_indent * indent, ' ')) +
|
||||||
|
ending;
|
||||||
|
else if (ending_valid && c_indent)
|
||||||
|
c_indent--;
|
||||||
|
}
|
||||||
|
auto is_end_set = kLangtoBlockStartsEnd.find(editor->lang.name);
|
||||||
|
auto is_start_set = kLangtoBlockStartsStart.find(editor->lang.name);
|
||||||
|
bool is_end = false;
|
||||||
|
if (is_end_set != kLangtoBlockStartsEnd.end())
|
||||||
|
for (auto end : is_end_set->second)
|
||||||
|
if (ends_with(before, end)) {
|
||||||
|
c_indent++;
|
||||||
|
is_end = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!is_end && is_start_set != kLangtoBlockStartsStart.end())
|
||||||
|
for (auto end : is_start_set->second)
|
||||||
|
if (starts_with(before, end)) {
|
||||||
|
c_indent++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
formatted = "\n" +
|
||||||
|
(indent == 1 ? std::string(c_indent, '\t')
|
||||||
|
: std::string(c_indent * indent, ' ')) +
|
||||||
|
ending;
|
||||||
|
Coord new_cursor = {cursor.row + 1, c_indent * indent};
|
||||||
|
edit_replace(editor, cursor, {cursor.row, len}, formatted.data(),
|
||||||
|
formatted.size());
|
||||||
|
editor->cursor = new_cursor;
|
||||||
|
editor->cursor_preffered = UINT32_MAX;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
if (!editor->lsp || !editor->lsp->allow_formatting_on_type)
|
||||||
|
return;
|
||||||
|
for (char ch : editor->lsp->format_chars) {
|
||||||
|
if (ch == '\n') {
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t col = utf8_offset_to_utf16(line, line_len, editor->cursor.col);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
int version = editor->lsp_version;
|
||||||
|
json message = {
|
||||||
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", "textDocument/onTypeFormatting"},
|
||||||
|
{"params",
|
||||||
|
{{"textDocument", {{"uri", editor->uri}}},
|
||||||
|
{"position", {{"line", editor->cursor.row}, {"character", col}}},
|
||||||
|
{"ch", std::string(1, ch)},
|
||||||
|
{"options",
|
||||||
|
{{"tabSize", 2},
|
||||||
|
{"insertSpaces", true},
|
||||||
|
{"trimTrailingWhitespace", true},
|
||||||
|
{"trimFinalNewlines", true}}}}}};
|
||||||
|
LSPPending *pending = new LSPPending();
|
||||||
|
pending->editor = editor;
|
||||||
|
pending->method = "textDocument/onTypeFormatting";
|
||||||
|
pending->callback = [version](Editor *editor, std::string, json message) {
|
||||||
|
if (version != editor->lsp_version)
|
||||||
|
return;
|
||||||
|
auto &edits = message["result"];
|
||||||
|
if (edits.is_array()) {
|
||||||
|
std::vector<TextEdit> t_edits;
|
||||||
|
t_edits.reserve(edits.size());
|
||||||
|
for (auto &edit : edits) {
|
||||||
|
TextEdit t_edit;
|
||||||
|
t_edit.text = edit.value("newText", "");
|
||||||
|
t_edit.start.row = edit["range"]["start"]["line"];
|
||||||
|
t_edit.start.col = edit["range"]["start"]["character"];
|
||||||
|
t_edit.end.row = edit["range"]["end"]["line"];
|
||||||
|
t_edit.end.col = edit["range"]["end"]["character"];
|
||||||
|
utf8_normalize_edit(editor, &t_edit);
|
||||||
|
t_edits.push_back(t_edit);
|
||||||
|
}
|
||||||
|
apply_lsp_edits(editor, t_edits, false);
|
||||||
|
ensure_scroll(editor);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lsp_send(editor->lsp, message, pending);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
110
src/editor/lsp.cc
Normal file
110
src/editor/lsp.cc
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#include "editor/decl.h"
|
||||||
|
#include "editor/editor.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
void apply_lsp_edits(Editor *editor, std::vector<TextEdit> edits, bool move) {
|
||||||
|
if (!edits.size())
|
||||||
|
return;
|
||||||
|
TextEdit first = edits[0];
|
||||||
|
Coord cursor = editor->cursor;
|
||||||
|
std::sort(
|
||||||
|
edits.begin(), edits.end(),
|
||||||
|
[](const TextEdit &a, const TextEdit &b) { return a.start > b.start; });
|
||||||
|
for (const auto &edit : edits)
|
||||||
|
edit_replace(editor, edit.start, edit.end, edit.text.c_str(),
|
||||||
|
edit.text.size());
|
||||||
|
if (move) {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
editor->cursor = first.start;
|
||||||
|
editor->cursor =
|
||||||
|
move_right(editor, editor->cursor,
|
||||||
|
count_clusters(first.text.c_str(), first.text.size(), 0,
|
||||||
|
first.text.size()));
|
||||||
|
} else {
|
||||||
|
if (cursor.row >= editor->root->line_count) {
|
||||||
|
editor->cursor.row = editor->root->line_count - 1;
|
||||||
|
editor->cursor.col = 0;
|
||||||
|
} else {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
uint32_t len;
|
||||||
|
line_to_byte(editor->root, cursor.row, &len);
|
||||||
|
len--;
|
||||||
|
editor->cursor.row = cursor.row;
|
||||||
|
editor->cursor.col = cursor.col < len ? cursor.col : len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void editor_lsp_handle(Editor *editor, json msg) {
|
||||||
|
if (msg.contains("method") &&
|
||||||
|
msg["method"] == "textDocument/publishDiagnostics") {
|
||||||
|
std::unique_lock lock(editor->v_mtx);
|
||||||
|
editor->warnings.clear();
|
||||||
|
json diagnostics = msg["params"]["diagnostics"];
|
||||||
|
for (size_t i = 0; i < diagnostics.size(); i++) {
|
||||||
|
json d = diagnostics[i];
|
||||||
|
VWarn w;
|
||||||
|
w.line = d["range"]["start"]["line"];
|
||||||
|
w.start = d["range"]["start"]["character"];
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, w.line);
|
||||||
|
if (!it)
|
||||||
|
continue;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
lock.unlock();
|
||||||
|
w.start = utf16_offset_to_utf8(line, len, w.start);
|
||||||
|
uint32_t end = d["range"]["end"]["character"];
|
||||||
|
if (d["range"]["end"]["line"] == w.line)
|
||||||
|
w.end = utf16_offset_to_utf8(line, len, end);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
std::string text = trim(d["message"].get<std::string>());
|
||||||
|
w.text_full = text;
|
||||||
|
auto pos = text.find('\n');
|
||||||
|
w.text = (pos == std::string::npos) ? text : text.substr(0, pos);
|
||||||
|
if (d.contains("source"))
|
||||||
|
w.source = d["source"].get<std::string>();
|
||||||
|
if (d.contains("code")) {
|
||||||
|
w.code = "[";
|
||||||
|
if (d["code"].is_string())
|
||||||
|
w.code += d["code"].get<std::string>() + "] ";
|
||||||
|
else if (d["code"].is_number())
|
||||||
|
w.code += std::to_string(d["code"].get<int>()) + "] ";
|
||||||
|
else
|
||||||
|
w.code.clear();
|
||||||
|
if (d.contains("codeDescription") &&
|
||||||
|
d["codeDescription"].contains("href"))
|
||||||
|
w.code += d["codeDescription"]["href"].get<std::string>();
|
||||||
|
}
|
||||||
|
if (d.contains("relatedInformation")) {
|
||||||
|
json related = d["relatedInformation"];
|
||||||
|
for (size_t j = 0; j < related.size(); j++) {
|
||||||
|
json rel = related[j];
|
||||||
|
std::string message = rel["message"].get<std::string>();
|
||||||
|
auto pos = message.find('\n');
|
||||||
|
message =
|
||||||
|
(pos == std::string::npos) ? message : message.substr(0, pos);
|
||||||
|
std::string uri = filename_from_path(
|
||||||
|
percent_decode(rel["location"]["uri"].get<std::string>()));
|
||||||
|
std::string row = std::to_string(
|
||||||
|
rel["location"]["range"]["start"]["line"].get<int>());
|
||||||
|
w.see_also.push_back(uri + ":" + row + ": " + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.type = 1;
|
||||||
|
if (d.contains("severity"))
|
||||||
|
w.type = d["severity"].get<int>();
|
||||||
|
editor->warnings.push_back(w);
|
||||||
|
}
|
||||||
|
std::sort(editor->warnings.begin(), editor->warnings.end());
|
||||||
|
editor->warnings_dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
120
src/editor/move_line.cc
Normal file
120
src/editor/move_line.cc
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
void move_line_up(Editor *editor) {
|
||||||
|
if (!editor || !editor->root || editor->cursor.row == 0)
|
||||||
|
return;
|
||||||
|
if (mode == NORMAL || mode == INSERT) {
|
||||||
|
uint32_t line_len, line_cluster_len;
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line) {
|
||||||
|
lock.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
line_cluster_len = count_clusters(line, line_len, 0, line_len);
|
||||||
|
uint32_t target_row = editor->cursor.row - 1;
|
||||||
|
uint32_t up_by = editor->cursor.row - target_row;
|
||||||
|
if (up_by > 1)
|
||||||
|
up_by--;
|
||||||
|
lock.unlock();
|
||||||
|
Coord cursor = editor->cursor;
|
||||||
|
edit_erase(editor, {cursor.row, 0}, line_cluster_len);
|
||||||
|
edit_erase(editor, {cursor.row, 0}, -1);
|
||||||
|
edit_insert(editor, {cursor.row - up_by, 0}, (char *)"\n", 1);
|
||||||
|
edit_insert(editor, {cursor.row - up_by, 0}, line, line_len);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
editor->cursor = {cursor.row - up_by, cursor.col};
|
||||||
|
} else if (mode == SELECT) {
|
||||||
|
uint32_t start_row = MIN(editor->cursor.row, editor->selection.row);
|
||||||
|
uint32_t end_row = MAX(editor->cursor.row, editor->selection.row);
|
||||||
|
uint32_t start_byte = line_to_byte(editor->root, start_row, nullptr);
|
||||||
|
uint32_t end_byte = line_to_byte(editor->root, end_row + 1, nullptr);
|
||||||
|
char *selected_text = read(editor->root, start_byte, end_byte - start_byte);
|
||||||
|
if (!selected_text)
|
||||||
|
return;
|
||||||
|
uint32_t selected_len = count_clusters(selected_text, end_byte - start_byte,
|
||||||
|
0, end_byte - start_byte);
|
||||||
|
Coord cursor = editor->cursor;
|
||||||
|
Coord selection = editor->selection;
|
||||||
|
edit_erase(editor, {start_row, 0}, selected_len);
|
||||||
|
edit_insert(editor, {start_row - 1, 0}, selected_text,
|
||||||
|
end_byte - start_byte);
|
||||||
|
free(selected_text);
|
||||||
|
editor->cursor = {cursor.row - 1, cursor.col};
|
||||||
|
editor->selection = {selection.row - 1, selection.col};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void move_line_down(Editor *editor) {
|
||||||
|
if (!editor || !editor->root)
|
||||||
|
return;
|
||||||
|
if (mode == NORMAL || mode == INSERT) {
|
||||||
|
if (editor->cursor.row >= editor->root->line_count - 1)
|
||||||
|
return;
|
||||||
|
uint32_t line_len, line_cluster_len;
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line) {
|
||||||
|
lock.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (line_len && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
line_cluster_len = count_clusters(line, line_len, 0, line_len);
|
||||||
|
uint32_t target_row = editor->cursor.row + 1;
|
||||||
|
if (target_row >= editor->root->line_count) {
|
||||||
|
free(line);
|
||||||
|
lock.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t down_by = target_row - editor->cursor.row;
|
||||||
|
if (down_by > 1)
|
||||||
|
down_by--;
|
||||||
|
uint32_t ln;
|
||||||
|
line_to_byte(editor->root, editor->cursor.row + down_by - 1, &ln);
|
||||||
|
lock.unlock();
|
||||||
|
Coord cursor = editor->cursor;
|
||||||
|
edit_erase(editor, {cursor.row, 0}, line_cluster_len);
|
||||||
|
edit_erase(editor, {cursor.row, 0}, -1);
|
||||||
|
edit_insert(editor, {cursor.row + down_by, 0}, (char *)"\n", 1);
|
||||||
|
edit_insert(editor, {cursor.row + down_by, 0}, line, line_len);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
editor->cursor = {cursor.row + down_by, cursor.col};
|
||||||
|
} else if (mode == SELECT) {
|
||||||
|
if (editor->cursor.row >= editor->root->line_count - 1 ||
|
||||||
|
editor->selection.row >= editor->root->line_count - 1)
|
||||||
|
return;
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
uint32_t start_row = MIN(editor->cursor.row, editor->selection.row);
|
||||||
|
uint32_t end_row = MAX(editor->cursor.row, editor->selection.row);
|
||||||
|
uint32_t target_row = end_row + 1;
|
||||||
|
if (target_row >= editor->root->line_count)
|
||||||
|
return;
|
||||||
|
uint32_t down_by = target_row - end_row;
|
||||||
|
if (down_by > 1)
|
||||||
|
down_by--;
|
||||||
|
uint32_t start_byte = line_to_byte(editor->root, start_row, nullptr);
|
||||||
|
uint32_t end_byte = line_to_byte(editor->root, end_row + 1, nullptr);
|
||||||
|
char *selected_text = read(editor->root, start_byte, end_byte - start_byte);
|
||||||
|
lock.unlock();
|
||||||
|
if (!selected_text)
|
||||||
|
return;
|
||||||
|
uint32_t selected_len = count_clusters(selected_text, end_byte - start_byte,
|
||||||
|
0, end_byte - start_byte);
|
||||||
|
Coord cursor = editor->cursor;
|
||||||
|
Coord selection = editor->selection;
|
||||||
|
edit_erase(editor, {start_row, 0}, selected_len);
|
||||||
|
edit_insert(editor, {start_row + down_by, 0}, selected_text,
|
||||||
|
end_byte - start_byte);
|
||||||
|
free(selected_text);
|
||||||
|
editor->cursor = {cursor.row + down_by, cursor.col};
|
||||||
|
editor->selection = {selection.row + down_by, selection.col};
|
||||||
|
}
|
||||||
|
}
|
||||||
487
src/editor/renderer.cc
Normal file
487
src/editor/renderer.cc
Normal file
@@ -0,0 +1,487 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "io/sysio.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "syntax/decl.h"
|
||||||
|
#include "syntax/parser.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
void render_editor(Editor *editor) {
|
||||||
|
uint32_t sel_start = 0, sel_end = 0;
|
||||||
|
std::shared_lock knot_lock(editor->knot_mtx);
|
||||||
|
uint32_t numlen =
|
||||||
|
EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1));
|
||||||
|
uint32_t render_width = editor->size.col - numlen;
|
||||||
|
uint32_t render_x = editor->position.col + numlen + 1;
|
||||||
|
std::vector<std::pair<uint32_t, char>> v;
|
||||||
|
for (size_t i = 0; i < 94; ++i)
|
||||||
|
if (editor->hooks[i] != 0)
|
||||||
|
v.push_back({editor->hooks[i], '!' + i});
|
||||||
|
std::sort(v.begin(), v.end());
|
||||||
|
auto hook_it = v.begin();
|
||||||
|
while (hook_it != v.end() && hook_it->first <= editor->scroll.row)
|
||||||
|
++hook_it;
|
||||||
|
std::unique_lock warn_lock(editor->v_mtx);
|
||||||
|
auto warn_it = editor->warnings.begin();
|
||||||
|
while (warn_it != editor->warnings.end() &&
|
||||||
|
warn_it->line < editor->scroll.row)
|
||||||
|
++warn_it;
|
||||||
|
std::unique_lock<std::mutex> lock;
|
||||||
|
if (editor->parser)
|
||||||
|
lock = std::unique_lock<std::mutex>(editor->parser->mutex);
|
||||||
|
LineData *line_data = nullptr;
|
||||||
|
auto get_type = [&](uint32_t col) {
|
||||||
|
if (!line_data)
|
||||||
|
return 0;
|
||||||
|
for (auto const &token : line_data->tokens)
|
||||||
|
if (token.start <= col && token.end > col)
|
||||||
|
return (int)token.type;
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
if (editor->selection_active) {
|
||||||
|
Coord start, end;
|
||||||
|
if (editor->cursor >= editor->selection) {
|
||||||
|
uint32_t prev_col, next_col;
|
||||||
|
switch (editor->selection_type) {
|
||||||
|
case CHAR:
|
||||||
|
start = editor->selection;
|
||||||
|
end = move_right(editor, editor->cursor, 1);
|
||||||
|
break;
|
||||||
|
case WORD:
|
||||||
|
word_boundaries(editor, editor->selection, &prev_col, &next_col,
|
||||||
|
nullptr, nullptr);
|
||||||
|
start = {editor->selection.row, prev_col};
|
||||||
|
end = editor->cursor;
|
||||||
|
break;
|
||||||
|
case LINE:
|
||||||
|
start = {editor->selection.row, 0};
|
||||||
|
end = editor->cursor;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
start = editor->cursor;
|
||||||
|
uint32_t prev_col, next_col, line_len;
|
||||||
|
switch (editor->selection_type) {
|
||||||
|
case CHAR:
|
||||||
|
end = move_right(editor, editor->selection, 1);
|
||||||
|
break;
|
||||||
|
case WORD:
|
||||||
|
word_boundaries(editor, editor->selection, &prev_col, &next_col,
|
||||||
|
nullptr, nullptr);
|
||||||
|
end = {editor->selection.row, next_col};
|
||||||
|
break;
|
||||||
|
case LINE:
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->selection.row);
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
return;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
end = {editor->selection.row, line_len};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sel_start = line_to_byte(editor->root, start.row, nullptr) + start.col;
|
||||||
|
sel_end = line_to_byte(editor->root, end.row, nullptr) + end.col;
|
||||||
|
}
|
||||||
|
Coord cursor = {UINT32_MAX, UINT32_MAX};
|
||||||
|
uint32_t line_index = editor->scroll.row;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, line_index);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t prev_col, next_col;
|
||||||
|
std::string word;
|
||||||
|
word_boundaries_exclusive(editor, editor->cursor, &prev_col, &next_col);
|
||||||
|
if (next_col - prev_col > 0 && next_col - prev_col < 256 - 4) {
|
||||||
|
uint32_t offset = line_to_byte(editor->root, editor->cursor.row, nullptr);
|
||||||
|
char *word_ptr = read(editor->root, offset + prev_col, next_col - prev_col);
|
||||||
|
if (word_ptr) {
|
||||||
|
word = std::string(word_ptr, next_col - prev_col);
|
||||||
|
free(word_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editor->extra_hl.render(editor->root, line_index, word, editor->is_css_color);
|
||||||
|
uint32_t rendered_rows = 0;
|
||||||
|
uint32_t global_byte_offset = line_to_byte(editor->root, line_index, nullptr);
|
||||||
|
while (rendered_rows < editor->size.row) {
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (editor->parser) {
|
||||||
|
if (line_data)
|
||||||
|
line_data = editor->parser->line_tree.next();
|
||||||
|
else
|
||||||
|
line_data = editor->parser->line_tree.start_iter(line_index);
|
||||||
|
}
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
uint32_t content_end = line_len;
|
||||||
|
while (content_end > 0 &&
|
||||||
|
(line[content_end - 1] == ' ' || line[content_end - 1] == '\t'))
|
||||||
|
content_end--;
|
||||||
|
uint32_t content_start = 0;
|
||||||
|
while (content_start < line_len &&
|
||||||
|
(line[content_start] == ' ' || line[content_start] == '\t'))
|
||||||
|
content_start++;
|
||||||
|
std::vector<VWarn> line_warnings;
|
||||||
|
while (warn_it != editor->warnings.end() && warn_it->line == line_index) {
|
||||||
|
line_warnings.push_back(*warn_it);
|
||||||
|
++warn_it;
|
||||||
|
}
|
||||||
|
uint32_t current_byte_offset = 0;
|
||||||
|
if (rendered_rows == 0)
|
||||||
|
current_byte_offset += editor->scroll.col;
|
||||||
|
while (current_byte_offset < line_len && rendered_rows < editor->size.row) {
|
||||||
|
uint32_t color = editor->cursor.row == line_index ? 0x222222 : 0;
|
||||||
|
if (current_byte_offset == 0 || rendered_rows == 0) {
|
||||||
|
const char *hook = nullptr;
|
||||||
|
char h[2] = {0, 0};
|
||||||
|
if (hook_it != v.end() && hook_it->first == line_index + 1) {
|
||||||
|
h[0] = hook_it->second;
|
||||||
|
hook = h;
|
||||||
|
hook_it++;
|
||||||
|
}
|
||||||
|
update(editor->position.row + rendered_rows, editor->position.col, hook,
|
||||||
|
0xAAAAAA, 0, 0);
|
||||||
|
char buf[16];
|
||||||
|
int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
|
||||||
|
uint32_t num_color =
|
||||||
|
editor->cursor.row == line_index ? 0xFFFFFF : 0x555555;
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
update(editor->position.row + rendered_rows, editor->position.col + i,
|
||||||
|
(char[2]){buf[i], 0}, num_color, 0, 0);
|
||||||
|
} else {
|
||||||
|
for (uint32_t i = 0; i < numlen + 1; i++)
|
||||||
|
update(editor->position.row + rendered_rows, editor->position.col + i,
|
||||||
|
" ", 0, 0, 0);
|
||||||
|
}
|
||||||
|
uint32_t col = 0;
|
||||||
|
uint32_t local_render_offset = 0;
|
||||||
|
uint32_t line_left = line_len - current_byte_offset;
|
||||||
|
while (line_left > 0 && col < render_width) {
|
||||||
|
if (line_index == editor->cursor.row &&
|
||||||
|
editor->cursor.col == (current_byte_offset + local_render_offset)) {
|
||||||
|
cursor.row = editor->position.row + rendered_rows;
|
||||||
|
cursor.col = render_x + col;
|
||||||
|
}
|
||||||
|
uint32_t absolute_byte_pos =
|
||||||
|
global_byte_offset + current_byte_offset + local_render_offset;
|
||||||
|
const Highlight *hl = nullptr;
|
||||||
|
if (editor->parser)
|
||||||
|
hl = &highlights[get_type(current_byte_offset + local_render_offset)];
|
||||||
|
std::optional<std::pair<uint32_t, uint32_t>> extra =
|
||||||
|
editor->extra_hl.get(
|
||||||
|
{line_index, current_byte_offset + local_render_offset});
|
||||||
|
uint32_t fg = extra && extra->second != UINT32_MAX
|
||||||
|
? extra->first
|
||||||
|
: (hl ? hl->fg : 0xFFFFFF);
|
||||||
|
uint32_t bg = extra && extra->second != UINT32_MAX
|
||||||
|
? extra->second
|
||||||
|
: (hl ? hl->bg : 0x000000);
|
||||||
|
uint8_t fl =
|
||||||
|
(hl ? hl->flags : 0) |
|
||||||
|
(extra ? (extra->second != UINT32_MAX ? CF_BOLD : CF_UNDERLINE)
|
||||||
|
: 0);
|
||||||
|
if (editor->selection_active && absolute_byte_pos >= sel_start &&
|
||||||
|
absolute_byte_pos < sel_end)
|
||||||
|
bg = bg | 0x555555;
|
||||||
|
uint32_t u_color = 0;
|
||||||
|
for (const auto &w : line_warnings) {
|
||||||
|
if (w.start <= current_byte_offset + local_render_offset &&
|
||||||
|
current_byte_offset + local_render_offset < w.end) {
|
||||||
|
switch (w.type) {
|
||||||
|
case 1:
|
||||||
|
u_color = 0xff0000;
|
||||||
|
fl |= CF_UNDERLINE;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
u_color = 0xffff00;
|
||||||
|
fl |= CF_UNDERLINE;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
u_color = 0xff00ff;
|
||||||
|
fl |= CF_UNDERLINE;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
u_color = 0xA0A0A0;
|
||||||
|
fl |= CF_UNDERLINE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
||||||
|
line + current_byte_offset + local_render_offset, line_left);
|
||||||
|
std::string cluster(line + current_byte_offset + local_render_offset,
|
||||||
|
cluster_len);
|
||||||
|
int width = display_width(cluster.c_str(), cluster_len);
|
||||||
|
if (col + width > render_width)
|
||||||
|
break;
|
||||||
|
if (current_byte_offset + local_render_offset >= content_start &&
|
||||||
|
current_byte_offset + local_render_offset < content_end) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col,
|
||||||
|
cluster.c_str(), fg, bg | color, fl, u_color);
|
||||||
|
} else {
|
||||||
|
if (cluster[0] == ' ') {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, "·",
|
||||||
|
0x282828, bg | color, fl, u_color);
|
||||||
|
} else {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, "-> ",
|
||||||
|
0x282828, bg | color, (fl & ~CF_BOLD) | CF_ITALIC, u_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
local_render_offset += cluster_len;
|
||||||
|
line_left -= cluster_len;
|
||||||
|
col += width;
|
||||||
|
while (width-- > 1)
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col - width,
|
||||||
|
"\x1b", fg, bg | color, fl);
|
||||||
|
}
|
||||||
|
if (line_index == editor->cursor.row &&
|
||||||
|
editor->cursor.col == (current_byte_offset + local_render_offset)) {
|
||||||
|
cursor.row = editor->position.row + rendered_rows;
|
||||||
|
cursor.col = render_x + col;
|
||||||
|
}
|
||||||
|
if (editor->selection_active &&
|
||||||
|
global_byte_offset + line_len + 1 > sel_start &&
|
||||||
|
global_byte_offset + line_len + 1 <= sel_end && col < render_width) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ", 0,
|
||||||
|
0x555555 | color, 0);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
if (!line_warnings.empty() && line_left == 0) {
|
||||||
|
VWarn warn = line_warnings.front();
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ", 0,
|
||||||
|
color, 0);
|
||||||
|
col++;
|
||||||
|
for (size_t i = 0; i < line_warnings.size(); i++) {
|
||||||
|
if (line_warnings[i].type < warn.type)
|
||||||
|
warn = line_warnings[i];
|
||||||
|
std::string err_sym = " ";
|
||||||
|
uint32_t fg_color = 0;
|
||||||
|
switch (line_warnings[i].type) {
|
||||||
|
case 1:
|
||||||
|
err_sym = "";
|
||||||
|
fg_color = 0xFF0000;
|
||||||
|
goto final;
|
||||||
|
case 2:
|
||||||
|
err_sym = "";
|
||||||
|
fg_color = 0xFFFF00;
|
||||||
|
goto final;
|
||||||
|
case 3:
|
||||||
|
err_sym = "";
|
||||||
|
fg_color = 0xFF00FF;
|
||||||
|
goto final;
|
||||||
|
case 4:
|
||||||
|
err_sym = "";
|
||||||
|
fg_color = 0xAAAAAA;
|
||||||
|
goto final;
|
||||||
|
final:
|
||||||
|
if (col < render_width) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col,
|
||||||
|
err_sym, fg_color, color, 0);
|
||||||
|
col++;
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ",
|
||||||
|
fg_color, color, 0);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (col < render_width) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ", 0,
|
||||||
|
0 | color, 0);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
size_t warn_idx = 0;
|
||||||
|
uint32_t fg_color = 0;
|
||||||
|
switch (warn.type) {
|
||||||
|
case 1:
|
||||||
|
fg_color = 0xFF0000;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
fg_color = 0xFFFF00;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
fg_color = 0xFF00FF;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
fg_color = 0xAAAAAA;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (col < render_width && warn_idx < warn.text.length()) {
|
||||||
|
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
||||||
|
warn.text.c_str() + warn_idx, warn.text.length() - warn_idx);
|
||||||
|
std::string cluster = warn.text.substr(warn_idx, cluster_len);
|
||||||
|
int width = display_width(cluster.c_str(), cluster_len);
|
||||||
|
if (col + width > render_width)
|
||||||
|
break;
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col,
|
||||||
|
cluster.c_str(), fg_color, color, 0);
|
||||||
|
col += width;
|
||||||
|
warn_idx += cluster_len;
|
||||||
|
while (width-- > 1)
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col - width,
|
||||||
|
"\x1b", fg_color, color, 0);
|
||||||
|
}
|
||||||
|
line_warnings.clear();
|
||||||
|
}
|
||||||
|
while (col < render_width) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ", 0,
|
||||||
|
0 | color, 0);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
rendered_rows++;
|
||||||
|
current_byte_offset += local_render_offset;
|
||||||
|
}
|
||||||
|
if (line_len == 0 ||
|
||||||
|
(current_byte_offset >= line_len && rendered_rows == 0)) {
|
||||||
|
uint32_t color = editor->cursor.row == line_index ? 0x222222 : 0;
|
||||||
|
const char *hook = nullptr;
|
||||||
|
char h[2] = {0, 0};
|
||||||
|
if (hook_it != v.end() && hook_it->first == line_index + 1) {
|
||||||
|
h[0] = hook_it->second;
|
||||||
|
hook = h;
|
||||||
|
hook_it++;
|
||||||
|
}
|
||||||
|
update(editor->position.row + rendered_rows, editor->position.col, hook,
|
||||||
|
0xAAAAAA, 0, 0);
|
||||||
|
char buf[16];
|
||||||
|
int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
|
||||||
|
uint32_t num_color =
|
||||||
|
editor->cursor.row == line_index ? 0xFFFFFF : 0x555555;
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
update(editor->position.row + rendered_rows, editor->position.col + i,
|
||||||
|
(char[2]){buf[i], 0}, num_color, 0, 0);
|
||||||
|
if (editor->cursor.row == line_index) {
|
||||||
|
cursor.row = editor->position.row + rendered_rows;
|
||||||
|
cursor.col = render_x;
|
||||||
|
}
|
||||||
|
uint32_t col = 0;
|
||||||
|
if (editor->selection_active &&
|
||||||
|
global_byte_offset + line_len + 1 > sel_start &&
|
||||||
|
global_byte_offset + line_len + 1 <= sel_end) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ", 0,
|
||||||
|
0x555555 | color, 0);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
if (!line_warnings.empty()) {
|
||||||
|
VWarn warn = line_warnings.front();
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ", 0,
|
||||||
|
color, 0);
|
||||||
|
col++;
|
||||||
|
for (size_t i = 0; i < line_warnings.size(); i++) {
|
||||||
|
if (line_warnings[i].type < warn.type)
|
||||||
|
warn = line_warnings[i];
|
||||||
|
std::string err_sym = " ";
|
||||||
|
uint32_t fg_color = 0;
|
||||||
|
switch (line_warnings[i].type) {
|
||||||
|
case 1:
|
||||||
|
err_sym = "";
|
||||||
|
fg_color = 0xFF0000;
|
||||||
|
goto final2;
|
||||||
|
case 2:
|
||||||
|
err_sym = "";
|
||||||
|
fg_color = 0xFFFF00;
|
||||||
|
goto final2;
|
||||||
|
case 3:
|
||||||
|
err_sym = "";
|
||||||
|
fg_color = 0xFF00FF;
|
||||||
|
goto final2;
|
||||||
|
case 4:
|
||||||
|
err_sym = "";
|
||||||
|
fg_color = 0xAAAAAA;
|
||||||
|
goto final2;
|
||||||
|
final2:
|
||||||
|
if (col < render_width) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col,
|
||||||
|
err_sym, fg_color, color, 0);
|
||||||
|
col++;
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ",
|
||||||
|
fg_color, color, 0);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (col < render_width) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ", 0,
|
||||||
|
0 | color, 0);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
size_t warn_idx = 0;
|
||||||
|
uint32_t fg_color = 0;
|
||||||
|
switch (warn.type) {
|
||||||
|
case 1:
|
||||||
|
fg_color = 0xFF0000;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
fg_color = 0xFFFF00;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
fg_color = 0xFF00FF;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
fg_color = 0xAAAAAA;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (col < render_width && warn_idx < warn.text.length()) {
|
||||||
|
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
||||||
|
warn.text.c_str() + warn_idx, warn.text.length() - warn_idx);
|
||||||
|
std::string cluster = warn.text.substr(warn_idx, cluster_len);
|
||||||
|
int width = display_width(cluster.c_str(), cluster_len);
|
||||||
|
if (col + width > render_width)
|
||||||
|
break;
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col,
|
||||||
|
cluster.c_str(), fg_color, color, 0);
|
||||||
|
col += width;
|
||||||
|
warn_idx += cluster_len;
|
||||||
|
while (width-- > 1)
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col - width,
|
||||||
|
"\x1b", fg_color, color, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (col < render_width) {
|
||||||
|
update(editor->position.row + rendered_rows, render_x + col, " ", 0,
|
||||||
|
0 | color, 0);
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
rendered_rows++;
|
||||||
|
}
|
||||||
|
global_byte_offset += line_len + 1;
|
||||||
|
line_index++;
|
||||||
|
}
|
||||||
|
if (lock.owns_lock())
|
||||||
|
lock.unlock();
|
||||||
|
while (rendered_rows < editor->size.row) {
|
||||||
|
for (uint32_t col = 0; col < editor->size.col; col++)
|
||||||
|
update(editor->position.row + rendered_rows, editor->position.col + col,
|
||||||
|
" ", 0xFFFFFF, 0, 0);
|
||||||
|
rendered_rows++;
|
||||||
|
}
|
||||||
|
if (cursor.row != UINT32_MAX && cursor.col != UINT32_MAX) {
|
||||||
|
int type = 0;
|
||||||
|
switch (mode) {
|
||||||
|
case NORMAL:
|
||||||
|
type = BLOCK;
|
||||||
|
break;
|
||||||
|
case INSERT:
|
||||||
|
type = CURSOR;
|
||||||
|
break;
|
||||||
|
case JUMPER:
|
||||||
|
case SELECT:
|
||||||
|
type = UNDERLINE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
set_cursor(cursor.row, cursor.col, type, true);
|
||||||
|
if (editor->completion.active && !editor->completion.box.hidden)
|
||||||
|
editor->completion.box.render(cursor);
|
||||||
|
else if (editor->hover_active)
|
||||||
|
editor->hover.render(cursor);
|
||||||
|
else if (editor->diagnostics_active)
|
||||||
|
editor->diagnostics.render(cursor);
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
if (editor->parser)
|
||||||
|
editor->parser->scroll(line_index + 5);
|
||||||
|
}
|
||||||
170
src/editor/scroll.cc
Normal file
170
src/editor/scroll.cc
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
|
||||||
|
void scroll_up(Editor *editor, int32_t number) {
|
||||||
|
if (!editor || number == 0)
|
||||||
|
return;
|
||||||
|
uint32_t numlen =
|
||||||
|
EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1));
|
||||||
|
uint32_t render_width = editor->size.col - numlen;
|
||||||
|
uint32_t line_index = editor->scroll.row;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, line_index);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
uint32_t len;
|
||||||
|
char *line = next_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
len--;
|
||||||
|
uint32_t current_byte_offset = 0;
|
||||||
|
uint32_t col = 0;
|
||||||
|
std::vector<uint32_t> segment_starts;
|
||||||
|
segment_starts.reserve(16);
|
||||||
|
if (current_byte_offset < editor->scroll.col)
|
||||||
|
segment_starts.push_back(0);
|
||||||
|
while (current_byte_offset < editor->scroll.col &&
|
||||||
|
current_byte_offset < len) {
|
||||||
|
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
||||||
|
line + current_byte_offset, len - current_byte_offset);
|
||||||
|
int width = display_width(line + current_byte_offset, cluster_len);
|
||||||
|
if (col + width > render_width) {
|
||||||
|
segment_starts.push_back(current_byte_offset);
|
||||||
|
col = 0;
|
||||||
|
}
|
||||||
|
current_byte_offset += cluster_len;
|
||||||
|
col += width;
|
||||||
|
}
|
||||||
|
for (auto it_seg = segment_starts.rbegin(); it_seg != segment_starts.rend();
|
||||||
|
++it_seg) {
|
||||||
|
if (--number == 0) {
|
||||||
|
editor->scroll = {line_index, *it_seg};
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
line = prev_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
editor->scroll = {0, 0};
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
line_index--;
|
||||||
|
line = prev_line(it, &len);
|
||||||
|
if (!line) {
|
||||||
|
editor->scroll = {0, 0};
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (len > 0 && line[len - 1] == '\n')
|
||||||
|
len--;
|
||||||
|
current_byte_offset = 0;
|
||||||
|
col = 0;
|
||||||
|
std::vector<uint32_t> segment_starts;
|
||||||
|
segment_starts.reserve(16);
|
||||||
|
segment_starts.push_back(0);
|
||||||
|
while (current_byte_offset < len) {
|
||||||
|
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
||||||
|
line + current_byte_offset, len - current_byte_offset);
|
||||||
|
int width = display_width(line + current_byte_offset, cluster_len);
|
||||||
|
if (col + width > render_width) {
|
||||||
|
segment_starts.push_back(current_byte_offset);
|
||||||
|
col = 0;
|
||||||
|
}
|
||||||
|
current_byte_offset += cluster_len;
|
||||||
|
col += width;
|
||||||
|
}
|
||||||
|
for (auto it_seg = segment_starts.rbegin(); it_seg != segment_starts.rend();
|
||||||
|
++it_seg) {
|
||||||
|
if (--number == 0) {
|
||||||
|
editor->scroll = {line_index, *it_seg};
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (number > 0);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void scroll_down(Editor *editor, uint32_t number) {
|
||||||
|
if (!editor || number == 0)
|
||||||
|
return;
|
||||||
|
uint32_t numlen =
|
||||||
|
EXTRA_META + static_cast<int>(std::log10(editor->root->line_count + 1));
|
||||||
|
uint32_t render_width = editor->size.col - numlen;
|
||||||
|
uint32_t line_index = editor->scroll.row;
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, line_index);
|
||||||
|
if (!it)
|
||||||
|
return;
|
||||||
|
const uint32_t max_visual_lines = editor->size.row;
|
||||||
|
Coord *scroll_queue = (Coord *)malloc(sizeof(Coord) * max_visual_lines);
|
||||||
|
uint32_t q_head = 0;
|
||||||
|
uint32_t q_size = 0;
|
||||||
|
uint32_t visual_seen = 0;
|
||||||
|
bool first_visual_line = true;
|
||||||
|
while (true) {
|
||||||
|
uint32_t line_len;
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
break;
|
||||||
|
if (line_len && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
uint32_t current_byte_offset = 0;
|
||||||
|
if (first_visual_line) {
|
||||||
|
current_byte_offset += editor->scroll.col;
|
||||||
|
first_visual_line = false;
|
||||||
|
}
|
||||||
|
while (current_byte_offset < line_len ||
|
||||||
|
(line_len == 0 && current_byte_offset == 0)) {
|
||||||
|
Coord coord = {line_index, current_byte_offset};
|
||||||
|
if (q_size < max_visual_lines) {
|
||||||
|
scroll_queue[(q_head + q_size) % max_visual_lines] = coord;
|
||||||
|
q_size++;
|
||||||
|
} else {
|
||||||
|
scroll_queue[q_head] = coord;
|
||||||
|
q_head = (q_head + 1) % max_visual_lines;
|
||||||
|
}
|
||||||
|
visual_seen++;
|
||||||
|
if (visual_seen >= number + max_visual_lines) {
|
||||||
|
editor->scroll = scroll_queue[q_head];
|
||||||
|
free(scroll_queue);
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t col = 0;
|
||||||
|
uint32_t local_render_offset = 0;
|
||||||
|
uint32_t left = line_len - current_byte_offset;
|
||||||
|
while (left > 0 && col < render_width) {
|
||||||
|
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
||||||
|
line + current_byte_offset + local_render_offset, left);
|
||||||
|
int width = display_width(
|
||||||
|
line + current_byte_offset + local_render_offset, cluster_len);
|
||||||
|
if (col + width > render_width)
|
||||||
|
break;
|
||||||
|
local_render_offset += cluster_len;
|
||||||
|
left -= cluster_len;
|
||||||
|
col += width;
|
||||||
|
}
|
||||||
|
current_byte_offset += local_render_offset;
|
||||||
|
if (line_len == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
line_index++;
|
||||||
|
}
|
||||||
|
if (q_size > 0) {
|
||||||
|
uint32_t advance = (q_size > number) ? number : (q_size - 1);
|
||||||
|
editor->scroll = scroll_queue[(q_head + advance) % max_visual_lines];
|
||||||
|
}
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
free(scroll_queue);
|
||||||
|
}
|
||||||
111
src/editor/selection.cc
Normal file
111
src/editor/selection.cc
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
void selection_bounds(Editor *editor, Coord *out_start, Coord *out_end) {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
Coord start, end;
|
||||||
|
if (editor->cursor >= editor->selection) {
|
||||||
|
uint32_t prev_col;
|
||||||
|
switch (editor->selection_type) {
|
||||||
|
case CHAR:
|
||||||
|
start = editor->selection;
|
||||||
|
end = move_right(editor, editor->cursor, 1);
|
||||||
|
break;
|
||||||
|
case WORD:
|
||||||
|
word_boundaries(editor, editor->selection, &prev_col, nullptr, nullptr,
|
||||||
|
nullptr);
|
||||||
|
start = {editor->selection.row, prev_col};
|
||||||
|
end = editor->cursor;
|
||||||
|
break;
|
||||||
|
case LINE:
|
||||||
|
start = {editor->selection.row, 0};
|
||||||
|
end = editor->cursor;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
start = editor->cursor;
|
||||||
|
uint32_t next_col, line_len;
|
||||||
|
switch (editor->selection_type) {
|
||||||
|
case CHAR:
|
||||||
|
end = move_right(editor, editor->selection, 1);
|
||||||
|
break;
|
||||||
|
case WORD:
|
||||||
|
word_boundaries(editor, editor->selection, nullptr, &next_col, nullptr,
|
||||||
|
nullptr);
|
||||||
|
end = {editor->selection.row, next_col};
|
||||||
|
break;
|
||||||
|
case LINE:
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->selection.row);
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
return;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
end = {editor->selection.row, line_len};
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (out_start)
|
||||||
|
*out_start = start;
|
||||||
|
if (out_end)
|
||||||
|
*out_end = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_selection(Editor *editor, uint32_t *out_len, Coord *out_start) {
|
||||||
|
std::shared_lock lock(editor->knot_mtx);
|
||||||
|
Coord start, end;
|
||||||
|
if (editor->cursor >= editor->selection) {
|
||||||
|
uint32_t prev_col;
|
||||||
|
switch (editor->selection_type) {
|
||||||
|
case CHAR:
|
||||||
|
start = editor->selection;
|
||||||
|
end = move_right(editor, editor->cursor, 1);
|
||||||
|
break;
|
||||||
|
case WORD:
|
||||||
|
word_boundaries(editor, editor->selection, &prev_col, nullptr, nullptr,
|
||||||
|
nullptr);
|
||||||
|
start = {editor->selection.row, prev_col};
|
||||||
|
end = editor->cursor;
|
||||||
|
break;
|
||||||
|
case LINE:
|
||||||
|
start = {editor->selection.row, 0};
|
||||||
|
end = editor->cursor;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
start = editor->cursor;
|
||||||
|
uint32_t next_col, line_len;
|
||||||
|
switch (editor->selection_type) {
|
||||||
|
case CHAR:
|
||||||
|
end = move_right(editor, editor->selection, 1);
|
||||||
|
break;
|
||||||
|
case WORD:
|
||||||
|
word_boundaries(editor, editor->selection, nullptr, &next_col, nullptr,
|
||||||
|
nullptr);
|
||||||
|
end = {editor->selection.row, next_col};
|
||||||
|
break;
|
||||||
|
case LINE:
|
||||||
|
LineIterator *it = begin_l_iter(editor->root, editor->selection.row);
|
||||||
|
char *line = next_line(it, &line_len);
|
||||||
|
if (!line)
|
||||||
|
return nullptr;
|
||||||
|
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||||
|
line_len--;
|
||||||
|
end = {editor->selection.row, line_len};
|
||||||
|
free(it->buffer);
|
||||||
|
free(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (out_start)
|
||||||
|
*out_start = start;
|
||||||
|
uint32_t start_byte =
|
||||||
|
line_to_byte(editor->root, start.row, nullptr) + start.col;
|
||||||
|
uint32_t end_byte = line_to_byte(editor->root, end.row, nullptr) + end.col;
|
||||||
|
char *text = read(editor->root, start_byte, end_byte - start_byte);
|
||||||
|
if (out_len)
|
||||||
|
*out_len = end_byte - start_byte;
|
||||||
|
return text;
|
||||||
|
}
|
||||||
37
src/editor/worker.cc
Normal file
37
src/editor/worker.cc
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include "editor/editor.h"
|
||||||
|
|
||||||
|
void hover_diagnostic(Editor *editor) {
|
||||||
|
std::shared_lock lock(editor->v_mtx);
|
||||||
|
static uint32_t last_line = UINT32_MAX;
|
||||||
|
if (last_line == editor->cursor.row && !editor->warnings_dirty)
|
||||||
|
return;
|
||||||
|
VWarn dummy;
|
||||||
|
dummy.line = editor->cursor.row;
|
||||||
|
editor->warnings_dirty = false;
|
||||||
|
last_line = editor->cursor.row;
|
||||||
|
auto first =
|
||||||
|
std::lower_bound(editor->warnings.begin(), editor->warnings.end(), dummy);
|
||||||
|
auto last =
|
||||||
|
std::upper_bound(editor->warnings.begin(), editor->warnings.end(), dummy);
|
||||||
|
std::vector<VWarn> warnings_at_line(first, last);
|
||||||
|
if (warnings_at_line.size() == 0) {
|
||||||
|
editor->diagnostics_active = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editor->diagnostics.clear();
|
||||||
|
editor->diagnostics.warnings.swap(warnings_at_line);
|
||||||
|
editor->diagnostics.render_first();
|
||||||
|
editor->diagnostics_active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void editor_worker(Editor *editor) {
|
||||||
|
if (!editor || !editor->root)
|
||||||
|
return;
|
||||||
|
if (editor->parser)
|
||||||
|
editor->parser->work();
|
||||||
|
hover_diagnostic(editor);
|
||||||
|
if (editor->completion.active && editor->completion.hover_dirty) {
|
||||||
|
editor->completion.hover.render_first();
|
||||||
|
editor->completion.hover_dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user