Compare commits
6 Commits
dd474cc38d
...
experiment
| Author | SHA1 | Date | |
|---|---|---|---|
| 013bffcad9 | |||
| 037f884050 | |||
|
c683754d49
|
|||
|
e9d164d769
|
|||
|
5b66f503e4
|
|||
|
d79ea4e75a
|
0
.gitattributes
vendored
Normal file → Executable file
0
.gitattributes
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
.gitmodules
vendored
Normal file → Executable file
0
.gitmodules
vendored
Normal file → Executable file
3
README.md
Normal file → Executable file
3
README.md
Normal file → Executable file
@@ -21,7 +21,7 @@ curl https://syedm.dev/crib | sh
|
||||
```
|
||||
|
||||
Currently only for Linux.<br>
|
||||
*Tested with arch linux and ubuntu and void*<br>
|
||||
*Tested with arch linux, ubuntu and void*<br>
|
||||
|
||||
## Building
|
||||
|
||||
@@ -134,6 +134,7 @@ crib ./filename.ext
|
||||
```
|
||||
|
||||
*If `filename.ext` does not exist, it will be created*<br>
|
||||
*memory usage is average case 10MB + 2x size of file*<br>
|
||||
|
||||
## Keybindings
|
||||
|
||||
|
||||
81
TODO.md
Normal file → Executable file
81
TODO.md
Normal file → Executable file
@@ -2,48 +2,52 @@ Copyright 2025 Syed Daanish
|
||||
|
||||
# TODO
|
||||
|
||||
# memory usage for debug build (release build will be smaller by about 25%)
|
||||
```
|
||||
8K -> 13.2M
|
||||
128K -> 13.2M (expected worst case 16.6M)
|
||||
128M -> 412.0M (expected worst case 2.3G)
|
||||
```
|
||||
|
||||
## Next few super long boring things to do::
|
||||
* redo lsp threads such that no mutex needed for any rope stuff (done)
|
||||
- Also make the classes own the methods in lsp (done)
|
||||
- This will mean that parsers/renderers and keystrokes will not need to be individually locked (done)
|
||||
- And so it will be much faster (done)
|
||||
- At which point the main thread can also be blocked on user input or lsp responses and still be fast
|
||||
* Add a superclass for editor called Window (which can be popup or tiled) (done)
|
||||
* Add a recursive tiling class for windows (done)
|
||||
* Handled by a single renderer that calls and renders each window (done)
|
||||
* Make editor's functions into its own methods (classify it) (done)
|
||||
- While at it
|
||||
- Seperate system functions into a class that branches to support local / ssh / server modes.
|
||||
- Even lsp shouldnt be directly controlled because it can branch on local and server modes
|
||||
- check wolfSSH stuff for remote editing
|
||||
- Thick and thin mode
|
||||
- thin mode only shares screen diffing over the network - uses server settings / themes
|
||||
- thick only shared fileio and lsp data with local used for all else - uses local settings / themes
|
||||
- Redo hooks as a engine of its own.
|
||||
- And factorize renderer into its own class (and make it just return an array of the render without knowing teh x,y)
|
||||
- which is just managed by the renderer
|
||||
- which is reused by scrollers/ensurers too
|
||||
- this will then allow inlay hints to be possible
|
||||
- and also make VAI easier to implement
|
||||
- And factorize renderer into its own class
|
||||
- which is just managed by the renderer
|
||||
- and adjusment.cc will call it
|
||||
- which is reused by scrollers/ensurers too (for knowing screen wrapped end)
|
||||
- this will then allow inlay hints to be possible
|
||||
- and also make VAI easier to implement
|
||||
* Allow keybinds to be set in ruby
|
||||
|
||||
* then the fun part:
|
||||
* ruby file for project specific runs alongside any system wide ones
|
||||
|
||||
- Seperate system functions into a class that branches to support local / ssh / server modes.
|
||||
- Even lsp shouldnt be directly controlled because it can branch on local and server modes
|
||||
- check libssh2 or child process stuff for remote editing (remote mode)
|
||||
- Thick and thin mode (server mode) (through ssh or port) (for website only port + webhook)
|
||||
- thin mode only shares screen diffing over the network - uses server settings / themes / shell
|
||||
- only one user connects at a time
|
||||
- provides data as a websocket with tui or gui/online modes where tui shares diffing as is (can be connected to by gui or website)
|
||||
- and gui/online modes try to (if not then render onto a canvas) forward window.render_gui() and dedicated windowing system (i.e windowing is html divs)
|
||||
- and window.render_gui() returns a markup code (custom markup)
|
||||
- and for events i could either leave tui as-is and for markup have special event handling or i
|
||||
- implement the widget system in both and have the same event handling then
|
||||
- actually for true cross platform i need to make a ui lib with widgets etc. so it is workable on all platforms (so they all need only a single ui lib)
|
||||
- thick only shared fileio and lsp data with local used for all else - uses local settings / themes
|
||||
- multiple users connect at once but maybe either make them not be allowed to open same file or make vscode like multiediting (unsure how exactly)
|
||||
- they all share same lsp instances
|
||||
- they all have the same shell access
|
||||
- allow having an instance that forwards thick mode to thin mode (to connect online mode to a thick server for code collaboration)
|
||||
* Then allow ruby code to create and handle windows as extentions
|
||||
* Then 3 inbuilt extentions being file manager, theme picker, tab selector
|
||||
|
||||
* make another tile type called tile tabbed that has a tab switcher and shows only one of its children at once
|
||||
* it takes focus and takes some keybinds for switching and forwards the rest (it also forwards the info and adds one for itself - the selected/total tabs)
|
||||
* also implement info strings for all the stuff that take focus
|
||||
|
||||
* Mode is a feild on a editor and there is no global "mode system" except in editors (enxtentions do their own thing)
|
||||
* make mode normal and not atomic if it is truly unused across threads
|
||||
* this means keybinds can be set to use the editor as insert mode only and so behave like vscode
|
||||
|
||||
* split lsp stuff into multiple files (not a monolithic class as it is now)
|
||||
* Extentions can also be used as file openers (for like databases . diffing . images . audio etc)
|
||||
* Local cache for state management (like undo history, cursor positions etc) (location can be set in config)
|
||||
* make sure to write inbuilt extentions in cpp and not ruby
|
||||
* also move default bar and clipboard back into cpp
|
||||
* all lsp popups are no longer their own classes but instead windows (extention like) in popup mode
|
||||
|
||||
* also **fix click handling to send mouse unclick to the same focus window as the click And also for drag to be same as the starter**
|
||||
* skip opening binary files
|
||||
* apply themeing in bg log bar lsp popus etc. to keep visual consistency
|
||||
* searching/replace/Multi-Cursor (for just one lsp command for all) with pcre2 with regex (started by a slash) (disabled for large files)
|
||||
@@ -116,8 +120,6 @@ Copyright 2025 Syed Daanish
|
||||
|
||||
* [ ] **Auto brace selection:** Add support for auto brace selection.
|
||||
|
||||
* [ ] **Tree-sitter Indent:** Attempt to allow Tree-sitter to handle indentation if possible.
|
||||
|
||||
### UX
|
||||
|
||||
* [ ] **Completion Filtering:**
|
||||
@@ -126,7 +128,7 @@ Copyright 2025 Syed Daanish
|
||||
|
||||
* [ ] **Basic Autocomplete:** Keep a list of words in the current buffer for non-LSP fallback.
|
||||
|
||||
### Major Features
|
||||
### Features
|
||||
|
||||
* [ ] **Search & Replace:**
|
||||
* [ ] Add Search/Replace UI.
|
||||
@@ -160,3 +162,14 @@ Copyright 2025 Syed Daanish
|
||||
* [ ] Switch JSON parser to `RapidJSON` (or similar high-performance lib).
|
||||
* [ ] Decrease usage of `std::string` in UI, LSP, warnings etc.
|
||||
* [ ] Also for vectors into managed memory especially for completions/lsp-stuff.
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- The pits of hell: -->
|
||||
<!-- * Replace perfectly working superfast rope with a structure that stores for small files everything -->
|
||||
<!-- - but for large ones it stores only what the user viewed / edited (by line number) -->
|
||||
<!-- - the rest is from the disk and not entirely loaded into memory (keep as option maybe they want everything in memory?) -->
|
||||
<!-- - also for the line mode still go through entire file to get and store line offsets -->
|
||||
<!-- - also it stores everything prolly still as rope tho (rope of lines) (or sparse map) -->
|
||||
<!-- - it stores the line text as-is which is only unicode / crlf normalized during usage -->
|
||||
|
||||
0
config/main.rb
Normal file → Executable file
0
config/main.rb
Normal file → Executable file
0
config/theme.rb
Normal file → Executable file
0
config/theme.rb
Normal file → Executable file
0
include/editor/completions.h
Normal file → Executable file
0
include/editor/completions.h
Normal file → Executable file
0
include/editor/decl.h
Normal file → Executable file
0
include/editor/decl.h
Normal file → Executable file
25
include/editor/editor.h
Normal file → Executable file
25
include/editor/editor.h
Normal file → Executable file
@@ -1,12 +1,15 @@
|
||||
#ifndef EDITOR_H
|
||||
#define EDITOR_H
|
||||
|
||||
#include "editor/hooks.h"
|
||||
#include "editor/indents.h"
|
||||
#include "editor/visual.h"
|
||||
#include "extentions/diagnostics.h"
|
||||
#include "extentions/hover.h"
|
||||
#include "io/knot.h"
|
||||
#include "io/sysio.h"
|
||||
#include "syntax/extras.h"
|
||||
#include "syntax/parser.h"
|
||||
#include "ui/diagnostics.h"
|
||||
#include "utils/utils.h"
|
||||
#include "windows/decl.h"
|
||||
|
||||
@@ -30,17 +33,17 @@ struct Editor : Window {
|
||||
Coord size = {0, 0};
|
||||
Coord scroll = {0, 0};
|
||||
Language lang = {};
|
||||
uint32_t hooks[94] = {0};
|
||||
bool jumper_set = false;
|
||||
std::vector<VWarn> warnings = {};
|
||||
bool warnings_dirty = false;
|
||||
VAI ai = {};
|
||||
std::shared_mutex lsp_mtx;
|
||||
std::atomic<struct LSPInstance *> lsp = nullptr;
|
||||
bool hover_active = false;
|
||||
bool diagnostics_active = false;
|
||||
HoverBox *hover_popup = init_hover();
|
||||
DiagnosticBox *diagnostic_popup = init_diagnostic();
|
||||
std::atomic<int> lsp_version = 1;
|
||||
IndentationEngine indents = {};
|
||||
HookEngine hooks = {};
|
||||
Parser *parser = nullptr;
|
||||
ExtraHighlighter extra_hl = {};
|
||||
bool is_css_color = false;
|
||||
@@ -83,7 +86,6 @@ struct Editor : Window {
|
||||
void backspace_edit();
|
||||
void delete_prev_word();
|
||||
void delete_next_word();
|
||||
void clear_hooks_at_line(uint32_t line);
|
||||
void cursor_prev_word();
|
||||
void cursor_next_word();
|
||||
void select_all();
|
||||
@@ -157,19 +159,6 @@ struct Editor : Window {
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
}
|
||||
|
||||
inline void apply_hook_insertion(uint32_t line, uint32_t rows) {
|
||||
for (auto &hook : this->hooks)
|
||||
if (hook > line)
|
||||
hook += rows;
|
||||
}
|
||||
|
||||
inline void apply_hook_deletion(uint32_t removal_start,
|
||||
uint32_t removal_end) {
|
||||
for (auto &hook : this->hooks)
|
||||
if (hook > removal_start)
|
||||
hook -= removal_end - removal_start + 1;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
0
include/editor/helpers.h
Normal file → Executable file
0
include/editor/helpers.h
Normal file → Executable file
91
include/editor/hooks.h
Executable file
91
include/editor/hooks.h
Executable file
@@ -0,0 +1,91 @@
|
||||
#ifndef EDITOR_HOOKS_H
|
||||
#define EDITOR_HOOKS_H
|
||||
|
||||
#include "utils/utils.h"
|
||||
|
||||
struct HookEngine {
|
||||
uint32_t hooks[94];
|
||||
std::vector<std::pair<uint32_t, char>> v;
|
||||
std::vector<std::pair<uint32_t, char>>::iterator it;
|
||||
|
||||
HookEngine() {
|
||||
for (int i = 0; i < 94; i++)
|
||||
hooks[i] = UINT32_MAX;
|
||||
v.reserve(94);
|
||||
}
|
||||
|
||||
inline void edit(uint32_t line, uint32_t removed_rows,
|
||||
uint32_t inserted_rows) {
|
||||
|
||||
int64_t delta = (int64_t)inserted_rows - (int64_t)removed_rows;
|
||||
for (int i = 0; i < 94; i++) {
|
||||
uint32_t &h = hooks[i];
|
||||
if (h == UINT32_MAX)
|
||||
continue;
|
||||
if (h < line)
|
||||
continue;
|
||||
if (removed_rows > 0 && h < line + removed_rows) {
|
||||
h = UINT32_MAX;
|
||||
continue;
|
||||
}
|
||||
h = (uint32_t)((int64_t)h + delta);
|
||||
}
|
||||
}
|
||||
|
||||
inline void set(char c, uint32_t line) {
|
||||
if (c < '!' || c > '~')
|
||||
return;
|
||||
int idx = c - '!';
|
||||
for (int i = 0; i < 94; i++) {
|
||||
if (hooks[i] == line) {
|
||||
hooks[i] = UINT32_MAX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
hooks[idx] = line;
|
||||
}
|
||||
|
||||
inline bool get(char c, uint32_t *out_line) const {
|
||||
if (c < '!' || c > '~')
|
||||
return false;
|
||||
uint32_t h = hooks[c - '!'];
|
||||
if (h == UINT32_MAX)
|
||||
return false;
|
||||
*out_line = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void clear_line(uint32_t line) {
|
||||
for (int i = 0; i < 94; i++)
|
||||
if (hooks[i] == line)
|
||||
hooks[i] = UINT32_MAX;
|
||||
}
|
||||
|
||||
inline void clear(char c) {
|
||||
if (c < '!' || c > '~')
|
||||
return;
|
||||
hooks[c - '!'] = UINT32_MAX;
|
||||
}
|
||||
|
||||
void start_iter(uint32_t scroll_line) {
|
||||
for (int i = 0; i < 94; i++)
|
||||
if (hooks[i] != UINT32_MAX)
|
||||
v.push_back({hooks[i], (char)('!' + i)});
|
||||
std::sort(v.begin(), v.end(),
|
||||
[](const auto &a, const auto &b) { return a.first < b.first; });
|
||||
it = std::lower_bound(
|
||||
v.begin(), v.end(), scroll_line,
|
||||
[](const auto &p, uint32_t line) { return p.first < line; });
|
||||
}
|
||||
|
||||
char next(uint32_t line_index) {
|
||||
if (it != v.end() && it->first == line_index) {
|
||||
char c = it->second;
|
||||
it++;
|
||||
return c;
|
||||
}
|
||||
return '\0';
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
0
include/editor/indents.h
Normal file → Executable file
0
include/editor/indents.h
Normal file → Executable file
113
include/editor/visual.h
Executable file
113
include/editor/visual.h
Executable file
@@ -0,0 +1,113 @@
|
||||
#include "editor/decl.h"
|
||||
#include "io/knot.h"
|
||||
#include "io/sysio.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
struct GraphemeIterator {
|
||||
char *line{nullptr};
|
||||
uint32_t len{0};
|
||||
|
||||
GraphemeIterator(char *line, uint32_t len) : line(line), len(len) {}
|
||||
|
||||
char *next(uint32_t *o_len, uint32_t *o_width) {
|
||||
if (!line || len == 0)
|
||||
return nullptr;
|
||||
char *cur = line;
|
||||
uint32_t g = grapheme_next_character_break_utf8(cur, len);
|
||||
if (o_width)
|
||||
*o_width = display_width(cur, g);
|
||||
if (o_len)
|
||||
*o_len = g;
|
||||
line += g;
|
||||
len -= g;
|
||||
return cur;
|
||||
}
|
||||
};
|
||||
|
||||
struct VisualIterator {
|
||||
LineIterator *it{nullptr};
|
||||
uint32_t line_index{UINT32_MAX};
|
||||
uint32_t offset{0};
|
||||
uint32_t len{0};
|
||||
bool first{true};
|
||||
char *line{nullptr};
|
||||
uint32_t render_width{io::cols};
|
||||
std::stack<std::pair<Coord, Coord>> prev_stack;
|
||||
|
||||
VisualIterator(Knot *root, Coord pos, uint32_t width)
|
||||
: it(begin_l_iter(root, pos.row)), line_index(pos.row - 1),
|
||||
offset(pos.col), render_width(width) {}
|
||||
|
||||
std::pair<Coord, Coord> prev() {
|
||||
if (!it)
|
||||
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
|
||||
if (prev_stack.empty())
|
||||
return _prev();
|
||||
auto ret = prev_stack.top();
|
||||
offset = ret.first.col;
|
||||
prev_stack.pop();
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::pair<Coord, Coord> _prev() {
|
||||
if (!it)
|
||||
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
|
||||
line_index--;
|
||||
line = prev_line(it, &len);
|
||||
if (!line)
|
||||
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
|
||||
if (len > 0 && line[len - 1] == '\n')
|
||||
len--;
|
||||
offset = first ? offset : 0;
|
||||
first = false;
|
||||
GraphemeIterator g(line + offset, len - offset);
|
||||
uint32_t o_len, o_width, rendered = 0, advance = 0;
|
||||
while (g.next(&o_len, &o_width)) {
|
||||
if (rendered + o_width > render_width) {
|
||||
prev_stack.push({{line_index, offset}, {line_index, offset + advance}});
|
||||
offset += advance;
|
||||
rendered = 0;
|
||||
advance = 0;
|
||||
}
|
||||
advance += o_len;
|
||||
rendered += o_width;
|
||||
}
|
||||
return {{line_index, offset}, {line_index, offset + advance}};
|
||||
}
|
||||
|
||||
std::pair<Coord, Coord> next() {
|
||||
if (!it)
|
||||
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
|
||||
if (!line) {
|
||||
line_index++;
|
||||
line = next_line(it, &len);
|
||||
if (!line)
|
||||
return {{UINT32_MAX, UINT32_MAX}, {UINT32_MAX, UINT32_MAX}};
|
||||
if (len > 0 && line[len - 1] == '\n')
|
||||
len--;
|
||||
offset = first ? offset : 0;
|
||||
first = false;
|
||||
}
|
||||
GraphemeIterator g(line + offset, len - offset);
|
||||
uint32_t o_len, o_width, rendered = 0, advance = 0;
|
||||
while (g.next(&o_len, &o_width)) {
|
||||
if (rendered + o_width > render_width) {
|
||||
offset += advance;
|
||||
return {{line_index, offset - advance}, {line_index, offset}};
|
||||
}
|
||||
advance += o_len;
|
||||
rendered += o_width;
|
||||
}
|
||||
offset += advance;
|
||||
if (offset >= len)
|
||||
line = nullptr;
|
||||
return {{line_index, offset}, {line_index, offset + advance}};
|
||||
}
|
||||
|
||||
~VisualIterator() {
|
||||
if (!it)
|
||||
return;
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
}
|
||||
};
|
||||
22
include/extentions/diagnostics.h
Executable file
22
include/extentions/diagnostics.h
Executable file
@@ -0,0 +1,22 @@
|
||||
#ifndef EXTENTION_DIAGNOSTICS_H
|
||||
#define EXTENTION_DIAGNOSTICS_H
|
||||
|
||||
#include "editor/decl.h"
|
||||
#include "io/sysio.h"
|
||||
#include "pch.h"
|
||||
#include "utils/utils.h"
|
||||
#include "windows/decl.h"
|
||||
|
||||
struct DiagnosticBox : Popup {
|
||||
std::vector<VWarn> warnings;
|
||||
|
||||
DiagnosticBox() { this->hidden = true; }
|
||||
void clear() { this->warnings.clear(); }
|
||||
void render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) override;
|
||||
void handle_click(KeyEvent, Coord) override { this->hidden = true; };
|
||||
~DiagnosticBox() {};
|
||||
};
|
||||
|
||||
DiagnosticBox *init_diagnostic();
|
||||
|
||||
#endif
|
||||
14
include/extentions/hover.h
Normal file → Executable file
14
include/extentions/hover.h
Normal file → Executable file
@@ -6,9 +6,7 @@
|
||||
#include "utils/utils.h"
|
||||
#include "windows/decl.h"
|
||||
|
||||
TileRoot *init_hover();
|
||||
|
||||
struct HoverBox : Window {
|
||||
struct HoverBox : Popup {
|
||||
std::string text;
|
||||
std::atomic<bool> is_markup;
|
||||
uint32_t scroll_;
|
||||
@@ -24,8 +22,16 @@ struct HoverBox : Window {
|
||||
}
|
||||
void scroll(int32_t number);
|
||||
void render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) override;
|
||||
void handle_click(KeyEvent, Coord) override { this->hidden = true; };
|
||||
void handle_click(KeyEvent ev, Coord) override {
|
||||
if (ev.mouse_button == SCROLL_BTN && ev.mouse_state == SCROLL) {
|
||||
this->scroll(ev.mouse_direction == SCROLL_UP ? -1 : 1);
|
||||
return;
|
||||
}
|
||||
this->hidden = true;
|
||||
};
|
||||
~HoverBox() {};
|
||||
};
|
||||
|
||||
HoverBox *init_hover();
|
||||
|
||||
#endif
|
||||
|
||||
0
include/io/knot.h
Normal file → Executable file
0
include/io/knot.h
Normal file → Executable file
7
include/io/sysio.h
Normal file → Executable file
7
include/io/sysio.h
Normal file → Executable file
@@ -96,14 +96,19 @@ inline bool is_empty_cell(const ScreenCell &c) {
|
||||
return c.utf8.empty() || c.utf8 == " " || c.utf8 == "\x1b";
|
||||
}
|
||||
|
||||
namespace io {
|
||||
extern std::vector<ScreenCell> new_screen;
|
||||
extern uint32_t rows, cols;
|
||||
extern bool show_cursor;
|
||||
extern std::vector<ScreenCell> old_screen;
|
||||
extern termios orig_termios;
|
||||
} // namespace io
|
||||
|
||||
Coord start_screen();
|
||||
void end_screen();
|
||||
void set_cursor(uint8_t row, uint8_t col, uint32_t type,
|
||||
bool show_cursor_param);
|
||||
void io_render();
|
||||
Coord get_size();
|
||||
|
||||
KeyEvent read_key();
|
||||
|
||||
|
||||
83
include/lsp/lsp.h
Normal file → Executable file
83
include/lsp/lsp.h
Normal file → Executable file
@@ -2,19 +2,15 @@
|
||||
#define LSP_H
|
||||
|
||||
#include "editor/editor.h"
|
||||
#include "main.h"
|
||||
#include "pch.h"
|
||||
#include "utils/utils.h"
|
||||
#include <cstdint>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define LSP_TIMEOUT 3000
|
||||
|
||||
namespace lsp {
|
||||
extern std::mutex lsp_mutex;
|
||||
extern std::unordered_map<std::string, std::unique_ptr<LSPInstance>>
|
||||
active_lsps;
|
||||
extern Queue<std::string> need_opening;
|
||||
extern std::unordered_set<std::string> opened;
|
||||
extern std::vector<Editor *> new_editors;
|
||||
} // namespace lsp
|
||||
#define LSP_TIMEOUT_START 3000
|
||||
#define LSP_TIMEOUT_QUIT_NORMAL 300
|
||||
#define LSP_TIMEOUT_QUIT_FORCE 80
|
||||
|
||||
void lsp_worker();
|
||||
|
||||
@@ -48,6 +44,16 @@ struct LSPMessage {
|
||||
std::function<void(const LSPMessage &)> callback;
|
||||
};
|
||||
|
||||
namespace lsp {
|
||||
extern std::mutex lsp_mutex;
|
||||
extern std::unordered_map<std::string, std::unique_ptr<LSPInstance>>
|
||||
active_lsps;
|
||||
extern Queue<std::string> need_opening;
|
||||
extern std::unordered_set<std::string> opened;
|
||||
extern std::vector<Editor *> new_editors;
|
||||
extern Queue<std::unique_ptr<LSPMessage>> response_queue;
|
||||
} // namespace lsp
|
||||
|
||||
struct LSPInstance {
|
||||
const LSP *lsp_info;
|
||||
std::string root_dir;
|
||||
@@ -70,7 +76,6 @@ struct LSPInstance {
|
||||
Queue<json> inbox;
|
||||
Queue<json> outbox;
|
||||
std::unordered_map<uint32_t, std::unique_ptr<LSPMessage>> pending;
|
||||
std::vector<std::unique_ptr<LSPMessage>> lsp_response_queue;
|
||||
std::vector<Editor *> editors;
|
||||
|
||||
LSPInstance(std::string lsp_id) {
|
||||
@@ -89,7 +94,15 @@ struct LSPInstance {
|
||||
{"capabilities", client_capabilities}}}};
|
||||
send_raw(initialize_message);
|
||||
pollfd pfd{stdout_fd, POLLIN, 0};
|
||||
poll(&pfd, 1, LSP_TIMEOUT);
|
||||
uint32_t waited = 0;
|
||||
while (waited < LSP_TIMEOUT_START) {
|
||||
poll(&pfd, 1, 50);
|
||||
if (pfd.revents & POLLIN)
|
||||
break;
|
||||
if (!running)
|
||||
return;
|
||||
waited += 50;
|
||||
}
|
||||
if (!(pfd.revents & POLLIN)) {
|
||||
exited = true;
|
||||
return;
|
||||
@@ -116,9 +129,7 @@ struct LSPInstance {
|
||||
}
|
||||
}
|
||||
allow_formatting = caps.value("documentFormattingProvider", false);
|
||||
if (lsp_id != "lua-language-server" /* Lua ls gives terrible ontype
|
||||
formatting so disable */
|
||||
&& caps.contains("documentOnTypeFormattingProvider")) {
|
||||
if (caps.contains("documentOnTypeFormattingProvider")) {
|
||||
auto &fmt = caps["documentOnTypeFormattingProvider"];
|
||||
if (fmt.is_object()) {
|
||||
if (fmt.contains("firstTriggerCharacter")) {
|
||||
@@ -181,34 +192,39 @@ struct LSPInstance {
|
||||
send_raw(initialized_message);
|
||||
}
|
||||
~LSPInstance() {
|
||||
uint32_t timeout =
|
||||
running ? LSP_TIMEOUT_QUIT_NORMAL : LSP_TIMEOUT_QUIT_FORCE;
|
||||
for (auto &ed : editors)
|
||||
ed->lsp.store(nullptr);
|
||||
initialized = false;
|
||||
exited = true;
|
||||
if (pid == -1)
|
||||
return;
|
||||
json shutdown = {{"id", ++last_id}, {"method", "shutdown"}};
|
||||
json shutdown = {
|
||||
{"jsonrpc", "2.0"}, {"id", ++last_id}, {"method", "shutdown"}};
|
||||
send_raw(shutdown);
|
||||
pollfd pfd{stdout_fd, POLLIN, 0};
|
||||
poll(&pfd, 1, 500);
|
||||
json exit_msg = {{"method", "exit"}};
|
||||
send_raw(exit_msg);
|
||||
int waited = 0;
|
||||
while (waited < 100) {
|
||||
int status;
|
||||
pid_t res = waitpid(pid, &status, WNOHANG);
|
||||
if (res == pid)
|
||||
break;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
waited += 10;
|
||||
poll(&pfd, 1, timeout);
|
||||
if (pfd.revents & POLLIN) {
|
||||
json exit_msg = {{"jsonrpc", "2.0"}, {"method", "exit"}};
|
||||
send_raw(exit_msg);
|
||||
uint32_t waited = 0;
|
||||
while (waited < timeout) {
|
||||
int status;
|
||||
pid_t res = waitpid(pid, &status, WNOHANG);
|
||||
if (res == pid)
|
||||
break;
|
||||
std::this_thread::sleep_for(10ms);
|
||||
waited += 10;
|
||||
}
|
||||
}
|
||||
close(stdin_fd);
|
||||
close(stdout_fd);
|
||||
if (kill(pid, 0) == 0) {
|
||||
kill(pid, SIGKILL);
|
||||
waitpid(pid, nullptr, 0);
|
||||
}
|
||||
pid = -1;
|
||||
close(stdin_fd);
|
||||
close(stdout_fd);
|
||||
}
|
||||
bool init_process() {
|
||||
int in_pipe[2];
|
||||
@@ -314,7 +330,7 @@ struct LSPInstance {
|
||||
if (it != pending.end()) {
|
||||
if (it->second->editor) {
|
||||
it->second->message = *msg;
|
||||
lsp_response_queue.push_back(std::move(it->second));
|
||||
lsp::response_queue.push(std::move(it->second));
|
||||
} else {
|
||||
auto message = *std::move(it->second);
|
||||
message.message = *msg;
|
||||
@@ -337,7 +353,7 @@ struct LSPInstance {
|
||||
response->message = *msg;
|
||||
response->callback = editor_handle_wrapper;
|
||||
if (ed)
|
||||
lsp_response_queue.push_back(std::move(response));
|
||||
lsp::response_queue.push(std::move(response));
|
||||
else
|
||||
lsp_handle(*msg);
|
||||
}
|
||||
@@ -346,11 +362,6 @@ struct LSPInstance {
|
||||
inline static void editor_handle_wrapper(const LSPMessage &message) {
|
||||
message.editor->lsp_handle(message.message);
|
||||
}
|
||||
void callbacks() {
|
||||
for (auto &message : lsp_response_queue)
|
||||
message->callback(*message);
|
||||
lsp_response_queue.clear();
|
||||
}
|
||||
inline void send_raw(const json &msg) {
|
||||
std::string payload = msg.dump();
|
||||
std::string header =
|
||||
|
||||
1
include/main.h
Normal file → Executable file
1
include/main.h
Normal file → Executable file
@@ -16,7 +16,6 @@ extern fs::path pwd;
|
||||
|
||||
namespace ui {
|
||||
extern Bar bar;
|
||||
extern TileRoot *hover_popup;
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
||||
|
||||
1
include/pch.h
Normal file → Executable file
1
include/pch.h
Normal file → Executable file
@@ -31,6 +31,7 @@ extern "C" {
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <immintrin.h>
|
||||
#include <limits.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
0
include/ruby/decl.h
Normal file → Executable file
0
include/ruby/decl.h
Normal file → Executable file
0
include/ruby/libcrib.rb
Normal file → Executable file
0
include/ruby/libcrib.rb
Normal file → Executable file
0
include/ruby/ruby_compiled.h
Normal file → Executable file
0
include/ruby/ruby_compiled.h
Normal file → Executable file
19
include/syntax/decl.h
Normal file → Executable file
19
include/syntax/decl.h
Normal file → Executable file
@@ -6,6 +6,8 @@
|
||||
#include "pch.h"
|
||||
#include "syntax/trie.h"
|
||||
|
||||
#define MAX_LINES_LOOKAROUND 512
|
||||
|
||||
struct Highlight {
|
||||
uint32_t fg{0xFFFFFF};
|
||||
uint32_t bg{0x000000};
|
||||
@@ -35,10 +37,23 @@ struct Token {
|
||||
TokenKind type;
|
||||
};
|
||||
|
||||
struct StateBase {
|
||||
virtual ~StateBase() = default;
|
||||
virtual std::unique_ptr<StateBase> clone() const = 0;
|
||||
};
|
||||
|
||||
struct CustomState : StateBase {
|
||||
std::string value;
|
||||
explicit CustomState(std::string v) : value(std::move(v)) {}
|
||||
std::unique_ptr<StateBase> clone() const override {
|
||||
return std::make_unique<CustomState>(value);
|
||||
}
|
||||
};
|
||||
|
||||
struct LineData {
|
||||
std::shared_ptr<void> in_state{nullptr};
|
||||
std::unique_ptr<StateBase> out_state;
|
||||
std::vector<Token> tokens;
|
||||
std::shared_ptr<void> out_state{nullptr};
|
||||
std::unique_ptr<StateBase> in_state;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
0
include/syntax/extras.h
Normal file → Executable file
0
include/syntax/extras.h
Normal file → Executable file
31
include/syntax/langs.h
Normal file → Executable file
31
include/syntax/langs.h
Normal file → Executable file
@@ -4,29 +4,19 @@
|
||||
#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);
|
||||
std::unique_ptr<StateBase> name##_parse( \
|
||||
std::vector<Token> *tokens, StateBase *in_state, const char *text, \
|
||||
uint32_t len, uint32_t line_num); \
|
||||
bool name##_state_match(StateBase *state_1, StateBase *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;
|
||||
template <typename B, typename A>
|
||||
std::unique_ptr<B> static_unique_ptr_cast(std::unique_ptr<A> &&p) {
|
||||
return std::unique_ptr<B>(static_cast<B *>(p.release()));
|
||||
}
|
||||
|
||||
DEF_LANG(ruby);
|
||||
@@ -34,11 +24,10 @@ 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,
|
||||
std::tuple<std::unique_ptr<StateBase> (*)(
|
||||
std::vector<Token> *tokens, StateBase *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)>>
|
||||
bool (*)(StateBase *state_1, StateBase *state_2)>>
|
||||
parsers = {
|
||||
LANG_A(ruby),
|
||||
LANG_A(bash),
|
||||
|
||||
136
include/syntax/line_map.h
Executable file
136
include/syntax/line_map.h
Executable file
@@ -0,0 +1,136 @@
|
||||
#ifndef LINE_MAP_H
|
||||
#define LINE_MAP_H
|
||||
|
||||
#include "syntax/decl.h"
|
||||
|
||||
struct LineKey {
|
||||
uint32_t line;
|
||||
uint32_t version;
|
||||
bool operator==(const LineKey &other) const {
|
||||
return line == other.line && version == other.version;
|
||||
}
|
||||
};
|
||||
|
||||
struct LineKeyHash {
|
||||
size_t operator()(const LineKey &key) const {
|
||||
uint64_t combined = (uint64_t(key.line) << 32) | key.version;
|
||||
return std::hash<uint64_t>()(combined);
|
||||
}
|
||||
};
|
||||
|
||||
struct EditDelta {
|
||||
uint32_t start_line;
|
||||
int64_t delta;
|
||||
};
|
||||
|
||||
struct LineMap {
|
||||
LineMap() : current_version(0) { edit_log.push_back({0, 0}); }
|
||||
|
||||
LineData *at(uint32_t line) {
|
||||
auto key_opt = resolve_line(line);
|
||||
if (!key_opt)
|
||||
return nullptr;
|
||||
LineKey key = *key_opt;
|
||||
if (key.version == current_version)
|
||||
return lines[key].get();
|
||||
auto data_ptr = std::move(lines[key]);
|
||||
lines.erase(key);
|
||||
key = {line, current_version};
|
||||
lines[key] = std::move(data_ptr);
|
||||
return lines[key].get();
|
||||
}
|
||||
|
||||
LineData *create_at(uint32_t line) {
|
||||
auto key_opt = resolve_line(line);
|
||||
LineKey key;
|
||||
std::unique_ptr<LineData> data_ptr;
|
||||
if (key_opt) {
|
||||
key = *key_opt;
|
||||
if (key.version == current_version)
|
||||
return lines[key].get();
|
||||
data_ptr = std::move(lines[key]);
|
||||
lines.erase(key);
|
||||
} else {
|
||||
data_ptr = std::make_unique<LineData>();
|
||||
}
|
||||
key = {line, current_version};
|
||||
lines[key] = std::move(data_ptr);
|
||||
return lines[key].get();
|
||||
}
|
||||
|
||||
void apply_edit(uint32_t start, int64_t delta) {
|
||||
if (delta < 0)
|
||||
batch_remove(start, -delta);
|
||||
current_version++;
|
||||
edit_log.push_back({start, delta});
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<LineKey, std::unique_ptr<LineData>, LineKeyHash> lines;
|
||||
|
||||
std::vector<EditDelta> edit_log;
|
||||
|
||||
uint32_t current_version;
|
||||
|
||||
void batch_remove(uint32_t line, uint32_t count) {
|
||||
std::vector<uint32_t> lines_t;
|
||||
lines_t.reserve(count);
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
lines_t.push_back(line + i);
|
||||
for (int64_t v = current_version; v >= 0; v--) {
|
||||
for (auto &l : lines_t) {
|
||||
if (l == UINT32_MAX)
|
||||
continue;
|
||||
LineKey key = {l, (uint32_t)v};
|
||||
if (lines.find(key) != lines.end()) {
|
||||
lines.erase(key);
|
||||
l = UINT32_MAX;
|
||||
}
|
||||
}
|
||||
bool all_removed = true;
|
||||
const auto &edit = edit_log[v];
|
||||
for (auto &l : lines_t) {
|
||||
if (l == UINT32_MAX)
|
||||
continue;
|
||||
all_removed = false;
|
||||
if (edit.delta > 0) {
|
||||
if (l >= edit.start_line) {
|
||||
if (l < edit.start_line + edit.delta)
|
||||
l = UINT32_MAX;
|
||||
else
|
||||
l -= edit.delta;
|
||||
}
|
||||
} else {
|
||||
if (l >= edit.start_line)
|
||||
l -= edit.delta;
|
||||
}
|
||||
}
|
||||
if (all_removed)
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::optional<LineKey> resolve_line(uint32_t line) {
|
||||
uint32_t current_line = line;
|
||||
for (int64_t v = current_version; v >= 0; v--) {
|
||||
LineKey key = {current_line, (uint32_t)v};
|
||||
if (lines.find(key) != lines.end())
|
||||
return key;
|
||||
const auto &edit = edit_log[v];
|
||||
if (edit.delta > 0) {
|
||||
if (current_line >= edit.start_line) {
|
||||
if (current_line < edit.start_line + edit.delta)
|
||||
return std::nullopt;
|
||||
current_line -= edit.delta;
|
||||
}
|
||||
} else {
|
||||
if (current_line >= edit.start_line)
|
||||
current_line -= edit.delta;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,232 +0,0 @@
|
||||
#ifndef LINE_TREE_H
|
||||
#define LINE_TREE_H
|
||||
|
||||
#include "syntax/decl.h"
|
||||
|
||||
struct LineTree {
|
||||
void clear() {
|
||||
clear_node(root);
|
||||
root = nullptr;
|
||||
stack_size = 0;
|
||||
}
|
||||
void build(uint32_t x) { root = build_node(x); }
|
||||
LineData *at(uint32_t x) {
|
||||
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) {
|
||||
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() {
|
||||
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) {
|
||||
if (x > subtree_size(root))
|
||||
x = subtree_size(root);
|
||||
root = insert_node(root, x, y);
|
||||
}
|
||||
void erase(uint32_t x, uint32_t y) {
|
||||
if (x + y > subtree_size(root))
|
||||
x = subtree_size(root) - y;
|
||||
root = erase_node(root, x, y);
|
||||
}
|
||||
uint32_t count() { 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;
|
||||
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
|
||||
16
include/syntax/parser.h
Normal file → Executable file
16
include/syntax/parser.h
Normal file → Executable file
@@ -3,24 +3,22 @@
|
||||
|
||||
#include "ruby/decl.h"
|
||||
#include "syntax/decl.h"
|
||||
#include "syntax/line_tree.h"
|
||||
#include "syntax/line_map.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);
|
||||
std::unique_ptr<StateBase> (*parse_func)(std::vector<Token> *tokens,
|
||||
StateBase *in_state,
|
||||
const char *text, uint32_t len,
|
||||
uint32_t line_num);
|
||||
bool (*state_match_func)(StateBase *state_1, StateBase *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{0};
|
||||
std::atomic<bool> scroll_dirty{false};
|
||||
LineTree line_tree;
|
||||
UniqueQueue<uint32_t> dirty_lines;
|
||||
LineMap line_map = LineMap();
|
||||
|
||||
Parser(Editor *editor, std::string n_lang, uint32_t n_scroll_max);
|
||||
void edit(uint32_t start_line, uint32_t removed_rows, uint32_t inserted_rows);
|
||||
|
||||
0
include/syntax/tokens.def
Normal file → Executable file
0
include/syntax/tokens.def
Normal file → Executable file
0
include/syntax/trie.h
Normal file → Executable file
0
include/syntax/trie.h
Normal file → Executable file
0
include/ui/bar.h
Normal file → Executable file
0
include/ui/bar.h
Normal file → Executable file
0
include/ui/completionbox.h
Normal file → Executable file
0
include/ui/completionbox.h
Normal file → Executable file
@@ -1,19 +0,0 @@
|
||||
#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
|
||||
13
include/utils/utils.h
Normal file → Executable file
13
include/utils/utils.h
Normal file → Executable file
@@ -6,18 +6,19 @@
|
||||
template <typename T> struct Queue {
|
||||
void push(T val) {
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
q.push(val);
|
||||
q.push(std::move(val));
|
||||
}
|
||||
std::optional<T> front() {
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
if (q.empty())
|
||||
return std::nullopt;
|
||||
return q.front();
|
||||
return std::move(q.front());
|
||||
}
|
||||
bool pop(T &val) {
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
if (q.empty())
|
||||
return false;
|
||||
val = q.front();
|
||||
val = std::move(q.front());
|
||||
q.pop();
|
||||
return true;
|
||||
}
|
||||
@@ -92,6 +93,11 @@ struct Coord {
|
||||
bool operator>=(const Coord &other) const { return !(*this < other); }
|
||||
};
|
||||
|
||||
static inline bool inside(Coord c, Coord pos, Coord size) {
|
||||
return c.row >= pos.row && c.col >= pos.col && c.row - pos.row < size.row &&
|
||||
c.col - pos.col < size.col;
|
||||
}
|
||||
|
||||
struct Match {
|
||||
size_t start;
|
||||
size_t end;
|
||||
@@ -132,6 +138,7 @@ 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 strip_newlines(const std::string &s);
|
||||
std::string substitute_fence(const std::string &documentation,
|
||||
const std::string &lang);
|
||||
|
||||
|
||||
27
include/windows/decl.h
Normal file → Executable file
27
include/windows/decl.h
Normal file → Executable file
@@ -22,6 +22,12 @@ struct Window : Tile {
|
||||
virtual std::array<std::string, 5> bar_info() { return {}; };
|
||||
};
|
||||
|
||||
struct Popup : Window {
|
||||
Coord pos;
|
||||
Coord size;
|
||||
virtual ~Popup() = default;
|
||||
};
|
||||
|
||||
struct TileBlock : Tile {
|
||||
bool vertical;
|
||||
std::vector<std::unique_ptr<Tile>> tiles;
|
||||
@@ -82,11 +88,12 @@ struct TileBlock : Tile {
|
||||
}
|
||||
};
|
||||
|
||||
struct TileRoot {
|
||||
struct TileBase {
|
||||
std::unique_ptr<Tile> tile;
|
||||
Coord pos;
|
||||
Coord size;
|
||||
|
||||
inline bool hidden() { return this->tile->hidden; }
|
||||
void render(std::vector<ScreenCell> &buffer) {
|
||||
if (this->tile->hidden)
|
||||
return;
|
||||
@@ -97,22 +104,14 @@ struct TileRoot {
|
||||
event.mouse_y -= this->pos.row;
|
||||
this->tile->handle_click(event, size);
|
||||
}
|
||||
bool inside(uint32_t x, uint32_t y) {
|
||||
return x >= pos.col && x < pos.col + size.col && y >= pos.row &&
|
||||
y < pos.row + size.row;
|
||||
}
|
||||
};
|
||||
|
||||
extern TileRoot root_tile;
|
||||
extern std::vector<std::unique_ptr<TileRoot>> popups;
|
||||
namespace layout {
|
||||
extern TileBase root_tile;
|
||||
extern Window *focused_window;
|
||||
|
||||
inline void close_popup(TileRoot *handle) {
|
||||
auto it = std::find_if(popups.begin(), popups.end(),
|
||||
[handle](const auto &p) { return p.get() == handle; });
|
||||
if (it != popups.end())
|
||||
popups.erase(it);
|
||||
}
|
||||
extern std::vector<std::unique_ptr<Popup>> popups;
|
||||
extern std::vector<std::unique_ptr<TileBase>> floating_tiles;
|
||||
} // namespace layout
|
||||
|
||||
void render();
|
||||
void handle_click(KeyEvent event);
|
||||
|
||||
0
installer.sh
Normal file → Executable file
0
installer.sh
Normal file → Executable file
0
libs/unicode_width/unicode_width.c
vendored
Normal file → Executable file
0
libs/unicode_width/unicode_width.c
vendored
Normal file → Executable file
0
libs/unicode_width/unicode_width.h
vendored
Normal file → Executable file
0
libs/unicode_width/unicode_width.h
vendored
Normal file → Executable file
0
samples/Makefile
Normal file → Executable file
0
samples/Makefile
Normal file → Executable file
0
samples/bash.sh
Normal file → Executable file
0
samples/bash.sh
Normal file → Executable file
0
samples/css.css
Normal file → Executable file
0
samples/css.css
Normal file → Executable file
0
samples/diff.patch
Normal file → Executable file
0
samples/diff.patch
Normal file → Executable file
0
samples/embedded_template.erb
Normal file → Executable file
0
samples/embedded_template.erb
Normal file → Executable file
0
samples/fish.fish
Normal file → Executable file
0
samples/fish.fish
Normal file → Executable file
0
samples/gdscript.gd
Normal file → Executable file
0
samples/gdscript.gd
Normal file → Executable file
0
samples/go.go
Normal file → Executable file
0
samples/go.go
Normal file → Executable file
0
samples/go.mod
Normal file → Executable file
0
samples/go.mod
Normal file → Executable file
0
samples/haskell.hs
Normal file → Executable file
0
samples/haskell.hs
Normal file → Executable file
0
samples/html.html
Normal file → Executable file
0
samples/html.html
Normal file → Executable file
0
samples/ini.ini
Normal file → Executable file
0
samples/ini.ini
Normal file → Executable file
0
samples/javascript.js
Normal file → Executable file
0
samples/javascript.js
Normal file → Executable file
0
samples/json.jsonc
Normal file → Executable file
0
samples/json.jsonc
Normal file → Executable file
0
samples/lua.lua
Normal file → Executable file
0
samples/lua.lua
Normal file → Executable file
0
samples/markdown.md
Normal file → Executable file
0
samples/markdown.md
Normal file → Executable file
0
samples/nginx.conf
Normal file → Executable file
0
samples/nginx.conf
Normal file → Executable file
0
samples/php.php
Normal file → Executable file
0
samples/php.php
Normal file → Executable file
0
samples/python.py
Normal file → Executable file
0
samples/python.py
Normal file → Executable file
0
samples/regex.regex
Normal file → Executable file
0
samples/regex.regex
Normal file → Executable file
1
samples/ruby.rb
Normal file → Executable file
1
samples/ruby.rb
Normal file → Executable file
@@ -339,6 +339,5 @@ puts 'Ruby syntax highlighting test complete.'
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
Anything here should be ignored >><<
|
||||
{{{}}}[[[]]](((000)))
|
||||
|
||||
0
samples/rust.rs
Normal file → Executable file
0
samples/rust.rs
Normal file → Executable file
0
samples/sample.gitattributes
Normal file → Executable file
0
samples/sample.gitattributes
Normal file → Executable file
0
samples/sample.gitignore
Normal file → Executable file
0
samples/sample.gitignore
Normal file → Executable file
0
samples/sql.sql
Normal file → Executable file
0
samples/sql.sql
Normal file → Executable file
0
samples/toml.toml
Normal file → Executable file
0
samples/toml.toml
Normal file → Executable file
0
samples/yaml.yaml
Normal file → Executable file
0
samples/yaml.yaml
Normal file → Executable file
71
src/editor/adjustment.cc
Normal file → Executable file
71
src/editor/adjustment.cc
Normal file → Executable file
@@ -2,72 +2,27 @@
|
||||
|
||||
void Editor::ensure_cursor() {
|
||||
if (this->cursor < this->scroll) {
|
||||
this->cursor.row = this->scroll.row;
|
||||
this->cursor.col = this->scroll.col;
|
||||
this->cursor = this->scroll;
|
||||
this->cursor_preffered = UINT32_MAX;
|
||||
return;
|
||||
}
|
||||
uint32_t numlen =
|
||||
EXTRA_META + static_cast<int>(std::log10(this->root->line_count + 1));
|
||||
uint32_t render_width = this->size.col - numlen;
|
||||
uint32_t visual_rows = 0;
|
||||
uint32_t line_index = this->scroll.row;
|
||||
bool first_visual_line = true;
|
||||
LineIterator *it = begin_l_iter(this->root, line_index);
|
||||
if (!it)
|
||||
return;
|
||||
Coord last_visible = this->scroll;
|
||||
while (true) {
|
||||
if (visual_rows >= this->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 ? this->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 >= this->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 == this->cursor.row) {
|
||||
if (this->cursor.col >= offset &&
|
||||
this->cursor.col <= offset + advance) {
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (advance == 0)
|
||||
break;
|
||||
offset += advance;
|
||||
if (line_len == 0)
|
||||
break;
|
||||
}
|
||||
line_index++;
|
||||
uint32_t render_height = 0;
|
||||
VisualIterator vis(root, scroll, render_width);
|
||||
std::pair<Coord, Coord> vline;
|
||||
Coord last_visible = scroll;
|
||||
while ((vline = vis.next()).first.row != UINT32_MAX &&
|
||||
render_height < this->size.row) {
|
||||
render_height++;
|
||||
last_visible = vline.first;
|
||||
if (cursor >= vline.first && cursor < vline.second)
|
||||
return;
|
||||
}
|
||||
this->cursor.row = last_visible.row;
|
||||
this->cursor.col = last_visible.col;
|
||||
cursor = last_visible;
|
||||
cursor_preffered = UINT32_MAX;
|
||||
this->cursor_preffered = UINT32_MAX;
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
}
|
||||
|
||||
void Editor::ensure_scroll() {
|
||||
|
||||
0
src/editor/boundaries.cc
Normal file → Executable file
0
src/editor/boundaries.cc
Normal file → Executable file
5
src/editor/click.cc
Normal file → Executable file
5
src/editor/click.cc
Normal file → Executable file
@@ -1,13 +1,10 @@
|
||||
#include "editor/editor.h"
|
||||
#include "main.h"
|
||||
|
||||
Coord Editor::click_coord(uint32_t x, uint32_t y) {
|
||||
if (mode == INSERT)
|
||||
x++;
|
||||
uint32_t numlen =
|
||||
EXTRA_META + static_cast<int>(std::log10(this->root->line_count + 1));
|
||||
uint32_t render_width = this->size.col - numlen;
|
||||
x = MAX(x, numlen) - numlen + 1;
|
||||
x = MAX(x, numlen) - numlen - 1;
|
||||
uint32_t target_visual_row = y;
|
||||
uint32_t visual_row = 0;
|
||||
uint32_t line_index = this->scroll.row;
|
||||
|
||||
0
src/editor/commands.cc
Normal file → Executable file
0
src/editor/commands.cc
Normal file → Executable file
0
src/editor/completions.cc
Normal file → Executable file
0
src/editor/completions.cc
Normal file → Executable file
0
src/editor/cursor.cc
Normal file → Executable file
0
src/editor/cursor.cc
Normal file → Executable file
9
src/editor/edit.cc
Normal file → Executable file
9
src/editor/edit.cc
Normal file → Executable file
@@ -44,10 +44,10 @@ void Editor::edit_erase(Coord pos, int64_t len) {
|
||||
}
|
||||
uint32_t start_row = point.row;
|
||||
uint32_t end_row = pos.row;
|
||||
this->apply_hook_deletion(start_row + 1, end_row);
|
||||
this->root = erase(this->root, start, byte_pos - start);
|
||||
if (this->parser)
|
||||
this->parser->edit(start_row, end_row - start_row, 0);
|
||||
this->hooks.edit(start_row, end_row - start_row, 0);
|
||||
if (do_lsp) {
|
||||
auto lsp = this->lsp.load();
|
||||
if (lsp->incremental_sync) {
|
||||
@@ -113,10 +113,10 @@ void Editor::edit_erase(Coord pos, int64_t len) {
|
||||
}
|
||||
uint32_t start_row = pos.row;
|
||||
uint32_t end_row = point.row;
|
||||
this->apply_hook_deletion(start_row + 1, end_row);
|
||||
this->root = erase(this->root, byte_pos, end - byte_pos);
|
||||
if (this->parser)
|
||||
this->parser->edit(start_row, end_row - start_row, 0);
|
||||
this->hooks.edit(start_row, end_row - start_row, 0);
|
||||
if (do_lsp) {
|
||||
auto lsp = this->lsp.load();
|
||||
if (lsp->incremental_sync) {
|
||||
@@ -169,9 +169,9 @@ void Editor::edit_insert(Coord pos, char *data, uint32_t len) {
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
if (data[i] == '\n')
|
||||
rows++;
|
||||
this->apply_hook_insertion(pos.row, rows);
|
||||
if (this->parser)
|
||||
this->parser->edit(pos.row, 0, rows);
|
||||
this->hooks.edit(pos.row, 0, rows);
|
||||
auto lsp = this->lsp.load();
|
||||
if (lsp) {
|
||||
if (lsp->incremental_sync) {
|
||||
@@ -232,10 +232,9 @@ void Editor::edit_replace(Coord start, Coord end, const char *text,
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
if (text[i] == '\n')
|
||||
rows++;
|
||||
if (rows > 0)
|
||||
rows--;
|
||||
if (this->parser)
|
||||
this->parser->edit(start.row, end.row - start.row, rows);
|
||||
this->hooks.edit(start.row, end.row - start.row, rows);
|
||||
auto lsp = this->lsp.load();
|
||||
if (lsp) {
|
||||
if (lsp->incremental_sync) {
|
||||
|
||||
0
src/editor/editor.cc
Normal file → Executable file
0
src/editor/editor.cc
Normal file → Executable file
27
src/editor/events.cc
Normal file → Executable file
27
src/editor/events.cc
Normal file → Executable file
@@ -6,8 +6,8 @@
|
||||
|
||||
void Editor::handle_event(KeyEvent event) {
|
||||
uint8_t old_mode = mode;
|
||||
if (this->hover_active)
|
||||
this->hover_active = false;
|
||||
if (!this->hover_popup->hidden)
|
||||
this->hover_popup->hidden = true;
|
||||
if (event.key_type == KEY_SPECIAL) {
|
||||
switch (event.special_modifier) {
|
||||
case 0:
|
||||
@@ -67,12 +67,12 @@ void Editor::handle_event(KeyEvent event) {
|
||||
this->select_all();
|
||||
break;
|
||||
case CTRL('h'):
|
||||
static_cast<HoverBox *>(ui::hover_popup->tile.get())->scroll(-1);
|
||||
this->hover_active = true;
|
||||
this->hover_popup->scroll(-1);
|
||||
this->hover_popup->hidden = false;
|
||||
break;
|
||||
case CTRL('l'):
|
||||
static_cast<HoverBox *>(ui::hover_popup->tile.get())->scroll(1);
|
||||
this->hover_active = true;
|
||||
this->hover_popup->scroll(1);
|
||||
this->hover_popup->hidden = false;
|
||||
break;
|
||||
case 'h':
|
||||
this->fetch_lsp_hover();
|
||||
@@ -96,7 +96,7 @@ void Editor::handle_event(KeyEvent event) {
|
||||
this->jumper_set = false;
|
||||
break;
|
||||
case 'N':
|
||||
this->clear_hooks_at_line(this->cursor.row);
|
||||
this->hooks.clear_line(this->cursor.row);
|
||||
break;
|
||||
case 's':
|
||||
case 'v':
|
||||
@@ -218,18 +218,11 @@ void Editor::handle_event(KeyEvent event) {
|
||||
if (event.key_type == KEY_CHAR && event.len == 1 &&
|
||||
(event.c[0] >= '!' && event.c[0] <= '~')) {
|
||||
if (this->jumper_set) {
|
||||
for (uint8_t i = 0; i < 94; i++)
|
||||
if (this->hooks[i] == this->cursor.row + 1) {
|
||||
this->hooks[i] = 0;
|
||||
break;
|
||||
}
|
||||
this->hooks[event.c[0] - '!'] = this->cursor.row + 1;
|
||||
this->hooks.set(event.c[0], this->cursor.row);
|
||||
} else {
|
||||
uint32_t line = this->hooks[event.c[0] - '!'] - 1;
|
||||
if (line > 0) {
|
||||
uint32_t line;
|
||||
if (this->hooks.get(event.c[0], &line))
|
||||
this->cursor = {line, 0};
|
||||
this->cursor_preffered = UINT32_MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
mode = NORMAL;
|
||||
|
||||
0
src/editor/fluff.cc
Executable file
0
src/editor/fluff.cc
Executable file
21
src/editor/helpers.cc
Normal file → Executable file
21
src/editor/helpers.cc
Normal file → Executable file
@@ -312,14 +312,6 @@ void Editor::delete_next_word() {
|
||||
this->edit_erase(this->cursor, next_col_cluster);
|
||||
}
|
||||
|
||||
void Editor::clear_hooks_at_line(uint32_t line) {
|
||||
for (uint8_t i = 0; i < 94; i++)
|
||||
if (this->hooks[i] == line + 1) {
|
||||
this->hooks[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::cursor_prev_word() {
|
||||
uint32_t prev_col;
|
||||
word_boundaries(this->cursor, &prev_col, nullptr, nullptr, nullptr);
|
||||
@@ -410,11 +402,10 @@ void Editor::fetch_lsp_hover() {
|
||||
hover_text += contents.get<std::string>();
|
||||
}
|
||||
if (!hover_text.empty()) {
|
||||
auto hover_box = static_cast<HoverBox *>(ui::hover_popup->tile.get());
|
||||
hover_box->clear();
|
||||
hover_box->text = clean_text(hover_text);
|
||||
hover_box->is_markup = is_markup;
|
||||
message.editor->hover_active = true;
|
||||
message.editor->hover_popup->clear();
|
||||
message.editor->hover_popup->text = clean_text(hover_text);
|
||||
message.editor->hover_popup->is_markup = is_markup;
|
||||
message.editor->hover_popup->hidden = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -423,12 +414,14 @@ void Editor::fetch_lsp_hover() {
|
||||
}
|
||||
|
||||
void Editor::handle_click(KeyEvent event, Coord size) {
|
||||
focused_window = this;
|
||||
layout::focused_window = this;
|
||||
this->size = size;
|
||||
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 (!this->hover_popup->hidden)
|
||||
this->hover_popup->hidden = true;
|
||||
if (event.key_type == KEY_MOUSE) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
|
||||
0
src/editor/indents.cc
Normal file → Executable file
0
src/editor/indents.cc
Normal file → Executable file
0
src/editor/lsp.cc
Normal file → Executable file
0
src/editor/lsp.cc
Normal file → Executable file
0
src/editor/move_line.cc
Normal file → Executable file
0
src/editor/move_line.cc
Normal file → Executable file
52
src/editor/renderer.cc
Normal file → Executable file
52
src/editor/renderer.cc
Normal file → Executable file
@@ -11,14 +11,7 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
EXTRA_META + static_cast<int>(std::log10(this->root->line_count + 1));
|
||||
uint32_t render_width = size.col - numlen;
|
||||
uint32_t render_x = pos.col + numlen + 1;
|
||||
std::vector<std::pair<uint32_t, char>> v;
|
||||
for (size_t i = 0; i < 94; ++i)
|
||||
if (this->hooks[i] != 0)
|
||||
v.push_back({this->hooks[i], '!' + i});
|
||||
std::sort(v.begin(), v.end());
|
||||
auto hook_it = v.begin();
|
||||
while (hook_it != v.end() && hook_it->first <= this->scroll.row)
|
||||
++hook_it;
|
||||
this->hooks.start_iter(this->scroll.row);
|
||||
auto warn_it = this->warnings.begin();
|
||||
while (warn_it != this->warnings.end() && warn_it->line < this->scroll.row)
|
||||
++warn_it;
|
||||
@@ -31,7 +24,7 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
return (int)token.type;
|
||||
return 0;
|
||||
};
|
||||
Coord screen = get_size();
|
||||
Coord screen = {io::rows, io::cols};
|
||||
auto update = [&](uint32_t row, uint32_t col, std::string text, uint32_t fg,
|
||||
uint32_t bg, uint8_t flags, uint32_t u_color,
|
||||
uint32_t width) {
|
||||
@@ -115,12 +108,8 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
while (rendered_rows < this->size.row) {
|
||||
uint32_t line_len;
|
||||
char *line = next_line(it, &line_len);
|
||||
if (this->parser) {
|
||||
if (line_data)
|
||||
line_data = this->parser->line_tree.next();
|
||||
else
|
||||
line_data = this->parser->line_tree.start_iter(line_index);
|
||||
}
|
||||
if (this->parser)
|
||||
line_data = this->parser->line_map.at(line_index);
|
||||
if (!line)
|
||||
break;
|
||||
if (line_len > 0 && line[line_len - 1] == '\n')
|
||||
@@ -144,14 +133,9 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
while (current_byte_offset < line_len && rendered_rows < this->size.row) {
|
||||
uint32_t color = this->cursor.row == line_index ? 0x222222 : 0;
|
||||
if (current_byte_offset == 0 || rendered_rows == 0) {
|
||||
const char *hook = "";
|
||||
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(pos.row + rendered_rows, pos.col, hook, 0xAAAAAA, 0, 0, 0, 1);
|
||||
char hook = this->hooks.next(line_index);
|
||||
update(pos.row + rendered_rows, pos.col, {hook, 0}, 0xAAAAAA, 0, 0, 0,
|
||||
1);
|
||||
char buf[16];
|
||||
int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
|
||||
uint32_t num_color =
|
||||
@@ -341,14 +325,8 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
if (line_len == 0 ||
|
||||
(current_byte_offset >= line_len && rendered_rows == 0)) {
|
||||
uint32_t color = this->cursor.row == line_index ? 0x222222 : 0;
|
||||
const char *hook = "";
|
||||
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(pos.row + rendered_rows, pos.col, hook, 0xAAAAAA, 0, 0, 0, 1);
|
||||
char hook = this->hooks.next(line_index);
|
||||
update(pos.row + rendered_rows, pos.col, {hook, 0}, 0xAAAAAA, 0, 0, 0, 1);
|
||||
char buf[16];
|
||||
int len = snprintf(buf, sizeof(buf), "%*u ", numlen, line_index + 1);
|
||||
uint32_t num_color = this->cursor.row == line_index ? 0xFFFFFF : 0x555555;
|
||||
@@ -471,14 +449,10 @@ void Editor::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
break;
|
||||
}
|
||||
set_cursor(cursor.row, cursor.col, type, true);
|
||||
// if (this->completion.active && !this->completion.box.hidden)
|
||||
// this->completion.box.render(cursor);
|
||||
// else if (this->hover_active)
|
||||
// this->hover.render(cursor);
|
||||
// else if (this->diagnostics_active)
|
||||
// this->diagnostics.render(cursor);
|
||||
if (this->hover_active)
|
||||
ui::hover_popup->pos = cursor;
|
||||
if (!this->hover_popup->hidden)
|
||||
this->hover_popup->pos = cursor;
|
||||
if (!this->diagnostic_popup->hidden)
|
||||
this->diagnostic_popup->pos = cursor;
|
||||
}
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
|
||||
0
src/editor/scroll.cc
Normal file → Executable file
0
src/editor/scroll.cc
Normal file → Executable file
0
src/editor/selection.cc
Normal file → Executable file
0
src/editor/selection.cc
Normal file → Executable file
47
src/editor/worker.cc
Normal file → Executable file
47
src/editor/worker.cc
Normal file → Executable file
@@ -1,36 +1,33 @@
|
||||
#include "editor/editor.h"
|
||||
|
||||
// void hover_diagnostic(Editor *editor) {
|
||||
// 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 hover_diagnostic(Editor *editor) {
|
||||
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->diagnostic_popup->hidden = true;
|
||||
return;
|
||||
}
|
||||
editor->diagnostic_popup->clear();
|
||||
editor->diagnostic_popup->warnings.swap(warnings_at_line);
|
||||
editor->diagnostic_popup->hidden = false;
|
||||
}
|
||||
|
||||
void Editor::work() {
|
||||
if (!this->root)
|
||||
return;
|
||||
if (this->parser)
|
||||
this->parser->work();
|
||||
// hover_diagnostic(this);
|
||||
hover_diagnostic(this);
|
||||
// if (this->completion.active && this->completion.hover_dirty) {
|
||||
// this->completion.hover.render_first();
|
||||
// this->completion.hover_dirty = false;
|
||||
|
||||
0
src/extentions/completion.cc
Normal file → Executable file
0
src/extentions/completion.cc
Normal file → Executable file
187
src/extentions/diagnostics.cc
Executable file
187
src/extentions/diagnostics.cc
Executable file
@@ -0,0 +1,187 @@
|
||||
#include "extentions/diagnostics.h"
|
||||
#include <cstdint>
|
||||
|
||||
DiagnosticBox *init_diagnostic() {
|
||||
auto diagnostic = std::make_unique<DiagnosticBox>();
|
||||
diagnostic->pos = {0, 0};
|
||||
diagnostic->size = {1, 1};
|
||||
diagnostic->hidden = true;
|
||||
DiagnosticBox *ptr = diagnostic.get();
|
||||
layout::popups.push_back(std::move(diagnostic));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void DiagnosticBox::render(std::vector<ScreenCell> &buffer, Coord n_size,
|
||||
Coord n_pos) {
|
||||
pos = n_pos;
|
||||
size = n_size;
|
||||
int32_t start_row = (int32_t)pos.row - (int32_t)size.row;
|
||||
if (start_row < 0)
|
||||
start_row = pos.row + 1;
|
||||
int32_t start_col = pos.col;
|
||||
Coord screen_size = {io::rows, io::cols};
|
||||
if (start_col + size.col > screen_size.col) {
|
||||
start_col = screen_size.col - size.col;
|
||||
if (start_col < 0)
|
||||
start_col = 0;
|
||||
}
|
||||
pos.col = start_col;
|
||||
pos.row = start_row;
|
||||
if (warnings.empty())
|
||||
return;
|
||||
uint32_t longest_line = 8 + warnings[0].source.length();
|
||||
for (auto &warn : warnings) {
|
||||
uint32_t longest = 0;
|
||||
uint32_t cur = 0;
|
||||
for (char ch : warn.text_full)
|
||||
if (ch == '\n') {
|
||||
longest = MAX(longest, cur);
|
||||
cur = 0;
|
||||
} else {
|
||||
if (ch == '\t')
|
||||
cur += 3;
|
||||
++cur;
|
||||
}
|
||||
longest = MAX(longest, cur);
|
||||
longest_line = MAX(longest_line, longest + 7);
|
||||
longest_line = MAX(longest_line, (uint32_t)warn.code.length() + 4);
|
||||
for (auto &see_also : warn.see_also)
|
||||
longest_line = MAX(longest_line, (uint32_t)see_also.length() + 4);
|
||||
}
|
||||
uint32_t content_width = MIN(longest_line, 150u);
|
||||
size.col = content_width + 2;
|
||||
auto set = [&](uint32_t r, uint32_t c, std::string text, uint32_t fg,
|
||||
uint32_t bg, uint8_t flags, uint32_t width) {
|
||||
if (r < 0 || r >= size.row || c < 0 || c >= size.col)
|
||||
return;
|
||||
r += pos.row;
|
||||
c += pos.col;
|
||||
if (r < 0 || r >= screen_size.row || c < 0 || c >= screen_size.col)
|
||||
return;
|
||||
ScreenCell &cell = buffer[r * screen_size.col + c];
|
||||
cell.utf8 = std::move(text);
|
||||
cell.width = width;
|
||||
cell.fg = fg;
|
||||
cell.bg = bg;
|
||||
cell.flags = flags;
|
||||
cell.ul_color = 0;
|
||||
};
|
||||
uint32_t base_bg = 0;
|
||||
uint32_t border_fg = 0x82AAFF;
|
||||
uint32_t r = 0;
|
||||
if (warnings[0].source != "") {
|
||||
std::string src_txt = "Source: ";
|
||||
uint32_t i = 0;
|
||||
for (; i < 8 && i < content_width; i++)
|
||||
set(1, i + 1, (char[2]){src_txt[i], 0}, 0x3EAAFF, base_bg, 0, 1);
|
||||
for (; i < 8 + warnings[0].source.length() && i < content_width; i++)
|
||||
set(1, i + 1, (char[2]){warnings[0].source[i - 8], 0}, 0xffffff, base_bg,
|
||||
0, 1);
|
||||
while (i < content_width)
|
||||
set(1, ++i, " ", 0xffffff, base_bg, 0, 1);
|
||||
r++;
|
||||
}
|
||||
int idx = 1;
|
||||
for (auto &warn : warnings) {
|
||||
char buf[4];
|
||||
std::snprintf(buf, sizeof(buf), "%2d", idx % 100);
|
||||
std::string line_txt = std::string(buf) + ". ";
|
||||
for (uint32_t i = 0; i < line_txt.length(); i++)
|
||||
set(r + 1, i + 1, (char[2]){line_txt[i], 0}, 0xffffff, base_bg, 0, 1);
|
||||
if (r >= 23)
|
||||
break;
|
||||
const char *err_sym = "";
|
||||
uint32_t c_sym = 0xAAAAAA;
|
||||
switch (warn.type) {
|
||||
case 1:
|
||||
err_sym = "";
|
||||
c_sym = 0xFF0000;
|
||||
break;
|
||||
case 2:
|
||||
err_sym = "";
|
||||
c_sym = 0xFFFF00;
|
||||
break;
|
||||
case 3:
|
||||
err_sym = "";
|
||||
c_sym = 0xFF00FF;
|
||||
break;
|
||||
case 4:
|
||||
err_sym = "";
|
||||
c_sym = 0xAAAAAA;
|
||||
break;
|
||||
}
|
||||
std::string text = warn.text_full + " " + err_sym;
|
||||
uint32_t i = 0;
|
||||
while (i < text.length() && r < 23) {
|
||||
uint32_t c = 4;
|
||||
while (c < content_width && i < text.length()) {
|
||||
if (text[i] == '\n') {
|
||||
while (i < text.length() && text[i] == '\n')
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
uint32_t cluster_len = grapheme_next_character_break_utf8(
|
||||
text.c_str() + i, text.length() - i);
|
||||
std::string cluster = text.substr(i, cluster_len);
|
||||
int width = display_width(cluster.c_str(), cluster_len);
|
||||
if (c + width > content_width)
|
||||
break;
|
||||
set(r + 1, c + 1, cluster.c_str(), c_sym, base_bg, 0, width);
|
||||
c += width;
|
||||
i += cluster_len;
|
||||
for (int w = 1; w < width; w++)
|
||||
set(r + 1, c - w + 1, "\x1b", c_sym, base_bg, 0, 0);
|
||||
}
|
||||
while (c < content_width)
|
||||
set(r + 1, ++c, " ", 0xffffff, base_bg, 0, 1);
|
||||
r++;
|
||||
}
|
||||
if (r >= 23)
|
||||
break;
|
||||
if (warn.code != "") {
|
||||
uint32_t i = 0;
|
||||
for (; i < 5 && i < content_width; i++)
|
||||
set(r + 1, i, " ", 0x81cdc6, base_bg, 0, 1);
|
||||
for (; i < warn.code.length() + 5 && i < content_width; i++)
|
||||
set(r + 1, i, (char[2]){warn.code[i - 5], 0}, 0x81cdc6, base_bg, 0, 1);
|
||||
while (i <= content_width)
|
||||
set(r + 1, i++, " ", 0x81cdc6, base_bg, 0, 1);
|
||||
r++;
|
||||
}
|
||||
if (r >= 23)
|
||||
break;
|
||||
for (std::string &see_also : warn.see_also) {
|
||||
uint32_t fg = 0xB55EFF;
|
||||
uint8_t colon_count = 0;
|
||||
uint32_t i = 0;
|
||||
for (; i < 5 && i < content_width; i++)
|
||||
set(r + 1, i, " ", 0x81cdc6, base_bg, 0, 1);
|
||||
for (; i < see_also.length() + 5 && i < content_width; i++) {
|
||||
set(r + 1, i, (char[2]){see_also[i - 5], 0}, fg, base_bg, 0, 1);
|
||||
if (see_also[i] == ':')
|
||||
colon_count++;
|
||||
if (colon_count == 2)
|
||||
fg = 0xFFFFFF;
|
||||
}
|
||||
while (i <= content_width)
|
||||
set(r + 1, i++, " ", fg, base_bg, 0, 1);
|
||||
r++;
|
||||
if (r >= 23)
|
||||
break;
|
||||
};
|
||||
idx++;
|
||||
}
|
||||
size.row = 2 + r;
|
||||
set(0, 0, "┌", border_fg, base_bg, 0, 1);
|
||||
for (uint32_t i = 1; i < size.col - 1; i++)
|
||||
set(0, i, "─", border_fg, base_bg, 0, 1);
|
||||
set(0, size.col - 1, "┐", border_fg, base_bg, 0, 1);
|
||||
for (uint32_t r = 1; r < size.row - 1; r++) {
|
||||
set(r, 0, "│", border_fg, base_bg, 0, 1);
|
||||
set(r, size.col - 1, "│", border_fg, base_bg, 0, 1);
|
||||
}
|
||||
set(size.row - 1, 0, "└", border_fg, base_bg, 0, 1);
|
||||
for (uint32_t i = 1; i < size.col - 1; i++)
|
||||
set(size.row - 1, i, "─", border_fg, base_bg, 0, 1);
|
||||
set(size.row - 1, size.col - 1, "┘", border_fg, base_bg, 0, 1);
|
||||
}
|
||||
48
src/extentions/hover.cc
Normal file → Executable file
48
src/extentions/hover.cc
Normal file → Executable file
@@ -1,15 +1,16 @@
|
||||
#include "extentions/hover.h"
|
||||
#include "io/sysio.h"
|
||||
#include "syntax/decl.h"
|
||||
#include "windows/decl.h"
|
||||
|
||||
TileRoot *init_hover() {
|
||||
auto root = std::make_unique<TileRoot>();
|
||||
root->tile = std::make_unique<HoverBox>();
|
||||
root->pos = {0, 0};
|
||||
root->size = {1, 1};
|
||||
root->tile->hidden = true;
|
||||
popups.push_back(std::move(root));
|
||||
return popups.back().get();
|
||||
HoverBox *init_hover() {
|
||||
auto hover = std::make_unique<HoverBox>();
|
||||
hover->pos = {0, 0};
|
||||
hover->size = {1, 1};
|
||||
hover->hidden = true;
|
||||
HoverBox *ptr = hover.get();
|
||||
layout::popups.push_back(std::move(hover));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void HoverBox::scroll(int32_t number) {
|
||||
@@ -25,20 +26,25 @@ void HoverBox::scroll(int32_t number) {
|
||||
scroll_dirty = true;
|
||||
}
|
||||
|
||||
void HoverBox::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
void HoverBox::render(std::vector<ScreenCell> &buffer, Coord n_size,
|
||||
Coord n_pos) {
|
||||
pos = n_pos;
|
||||
size = n_size;
|
||||
if (scroll_dirty) {
|
||||
// TODO: call syntax highlighter here
|
||||
}
|
||||
// int32_t start_row = (int32_t)pos.row - (int32_t)size.row;
|
||||
// if (start_row < 0)
|
||||
// start_row = pos.row + 1;
|
||||
// int32_t start_col = pos.col; // pos here is the cursor pos
|
||||
Coord screen_size = get_size();
|
||||
// if (start_col + size.col > screen_size.col) {
|
||||
// start_col = screen_size.col - size.col;
|
||||
// if (start_col < 0)
|
||||
// start_col = 0;
|
||||
// }
|
||||
int32_t start_row = (int32_t)pos.row - (int32_t)size.row;
|
||||
if (start_row < 0)
|
||||
start_row = pos.row + 1;
|
||||
int32_t start_col = pos.col;
|
||||
Coord screen_size = {io::rows, io::cols};
|
||||
if (start_col + size.col > screen_size.col) {
|
||||
start_col = screen_size.col - size.col;
|
||||
if (start_col < 0)
|
||||
start_col = 0;
|
||||
}
|
||||
pos.col = start_col;
|
||||
pos.row = start_row;
|
||||
uint32_t longest_line = 0;
|
||||
uint32_t current_width = 0;
|
||||
for (size_t j = 0; j < text.length(); j++) {
|
||||
@@ -69,6 +75,8 @@ void HoverBox::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
return;
|
||||
r += pos.row;
|
||||
c += pos.col;
|
||||
if (r < 0 || r >= screen_size.row || c < 0 || c >= screen_size.col)
|
||||
return;
|
||||
ScreenCell &cell = buffer[r * screen_size.col + c];
|
||||
cell.utf8 = text;
|
||||
cell.width = width;
|
||||
@@ -103,6 +111,8 @@ void HoverBox::render(std::vector<ScreenCell> &buffer, Coord size, Coord pos) {
|
||||
for (int w = 1; w < width; w++)
|
||||
set(r + 1, c - w + 1, "\x1b", 0xFFFFFF, base_bg, 0, 0);
|
||||
}
|
||||
while (c < content_width)
|
||||
set(r + 1, ++c, " ", 0xFFFFFF, base_bg, 0, 0);
|
||||
r++;
|
||||
}
|
||||
if (scroll_dirty)
|
||||
|
||||
0
src/io/input.cc
Normal file → Executable file
0
src/io/input.cc
Normal file → Executable file
0
src/io/knot.cc
Normal file → Executable file
0
src/io/knot.cc
Normal file → Executable file
16
src/io/renderer.cc
Normal file → Executable file
16
src/io/renderer.cc
Normal file → Executable file
@@ -1,15 +1,19 @@
|
||||
#include "io/sysio.h"
|
||||
|
||||
namespace io {
|
||||
std::vector<ScreenCell> new_screen;
|
||||
static uint32_t rows, cols;
|
||||
static bool show_cursor = 0;
|
||||
static std::vector<ScreenCell> old_screen;
|
||||
static termios orig_termios;
|
||||
uint32_t rows, cols;
|
||||
bool show_cursor = 0;
|
||||
std::vector<ScreenCell> old_screen;
|
||||
termios orig_termios;
|
||||
} // namespace io
|
||||
|
||||
using namespace io;
|
||||
|
||||
void disable_raw_mode() {
|
||||
std::string os = "\x1b[?1049l\x1b[2 q\x1b[?1002l\x1b[?25h\x1b[?2004l";
|
||||
write(STDOUT_FILENO, os.c_str(), os.size());
|
||||
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) == -1) {
|
||||
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &io::orig_termios) == -1) {
|
||||
perror("tcsetattr");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -45,8 +49,6 @@ Coord start_screen() {
|
||||
|
||||
void end_screen() { disable_raw_mode(); }
|
||||
|
||||
Coord get_size() { return {rows, cols}; }
|
||||
|
||||
void io_render() {
|
||||
static bool first_render = true;
|
||||
uint32_t current_fg = 0;
|
||||
|
||||
0
src/lsp/handlers.cc
Normal file → Executable file
0
src/lsp/handlers.cc
Normal file → Executable file
0
src/lsp/process.cc
Normal file → Executable file
0
src/lsp/process.cc
Normal file → Executable file
1
src/lsp/worker.cc
Normal file → Executable file
1
src/lsp/worker.cc
Normal file → Executable file
@@ -6,6 +6,7 @@ std::unordered_map<std::string, std::unique_ptr<LSPInstance>> active_lsps;
|
||||
std::unordered_set<std::string> opened;
|
||||
Queue<std::string> need_opening;
|
||||
std::vector<Editor *> new_editors;
|
||||
Queue<std::unique_ptr<LSPMessage>> response_queue;
|
||||
} // namespace lsp
|
||||
|
||||
void lsp_worker() {
|
||||
|
||||
78
src/main.cc
Normal file → Executable file
78
src/main.cc
Normal file → Executable file
@@ -1,6 +1,5 @@
|
||||
#include "main.h"
|
||||
#include "editor/editor.h"
|
||||
#include "extentions/hover.h"
|
||||
#include "io/sysio.h"
|
||||
#include "lsp/lsp.h"
|
||||
#include "ruby/decl.h"
|
||||
@@ -9,18 +8,16 @@
|
||||
#include "windows/decl.h"
|
||||
|
||||
std::atomic<bool> running{true};
|
||||
Queue<KeyEvent> event_queue;
|
||||
fs::path pwd;
|
||||
std::atomic<uint8_t> mode = NORMAL;
|
||||
fs::path pwd;
|
||||
|
||||
namespace ui {
|
||||
Bar bar;
|
||||
TileRoot *hover_popup = nullptr;
|
||||
} // namespace ui
|
||||
|
||||
void background_lsp() {
|
||||
while (running)
|
||||
throttle(8ms, lsp_worker);
|
||||
throttle(16ms, lsp_worker);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@@ -33,46 +30,57 @@ int main(int argc, char *argv[]) {
|
||||
const char *filename = (argc > 1) ? argv[1] : "";
|
||||
uint8_t eol = read_line_endings();
|
||||
|
||||
ui::hover_popup = init_hover();
|
||||
layout::root_tile.pos = {0, 0};
|
||||
layout::root_tile.size = {screen.row - 2, screen.col - 1};
|
||||
auto editor = std::make_unique<Editor>(filename, eol);
|
||||
layout::focused_window = editor.get();
|
||||
auto block = std::make_unique<TileBlock>();
|
||||
block->tiles.push_back(std::move(editor));
|
||||
layout::root_tile.tile = std::move(block);
|
||||
|
||||
root_tile.size = {screen.row - 2, screen.col - 1};
|
||||
root_tile.pos = {0, 0};
|
||||
|
||||
root_tile.tile = std::make_unique<Editor>(filename, eol);
|
||||
focused_window = static_cast<Editor *>(root_tile.tile.get());
|
||||
ui::bar.init(screen);
|
||||
|
||||
std::thread lsp_thread(background_lsp);
|
||||
|
||||
while (running) {
|
||||
KeyEvent event = throttle(1ms, read_key);
|
||||
if (event.key_type != KEY_NONE) {
|
||||
if (event.key_type == KEY_CHAR && event.len == 1 &&
|
||||
event.c[0] == CTRL('q')) {
|
||||
free(event.c);
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
if (mode != RUNNER) {
|
||||
if (event.key_type == KEY_MOUSE) {
|
||||
handle_click(event);
|
||||
} else {
|
||||
focused_window->handle_event(event);
|
||||
layout::focused_window->work();
|
||||
render();
|
||||
throttle(16ms, io_render);
|
||||
KeyEvent event;
|
||||
while (running && lsp::response_queue.empty() &&
|
||||
(event = read_key()).key_type == KEY_NONE)
|
||||
std::this_thread::sleep_for(1ms);
|
||||
uint8_t consumed = 0;
|
||||
do {
|
||||
if (event.key_type != KEY_NONE) {
|
||||
if (event.key_type == KEY_CHAR && event.len == 1 &&
|
||||
event.c[0] == CTRL('q')) {
|
||||
free(event.c);
|
||||
running = false;
|
||||
goto quit;
|
||||
}
|
||||
} else {
|
||||
ui::bar.handle_event(event);
|
||||
if (mode != RUNNER) {
|
||||
if (event.key_type == KEY_MOUSE) {
|
||||
handle_click(event);
|
||||
} else {
|
||||
layout::focused_window->handle_event(event);
|
||||
}
|
||||
} else {
|
||||
ui::bar.handle_event(event);
|
||||
}
|
||||
if ((event.key_type == KEY_CHAR || event.key_type == KEY_PASTE) &&
|
||||
event.c)
|
||||
free(event.c);
|
||||
}
|
||||
if ((event.key_type == KEY_CHAR || event.key_type == KEY_PASTE) &&
|
||||
event.c)
|
||||
free(event.c);
|
||||
}
|
||||
for (auto &lsp_inst : lsp::active_lsps)
|
||||
lsp_inst.second->callbacks();
|
||||
focused_window->work();
|
||||
throttle(4ms, render);
|
||||
throttle(4ms, io_render);
|
||||
} while (++consumed < 32 && (event = read_key()).key_type != KEY_NONE);
|
||||
std::unique_ptr<LSPMessage> msg;
|
||||
while (lsp::response_queue.pop(msg)) {
|
||||
msg->callback(*msg);
|
||||
};
|
||||
}
|
||||
|
||||
quit:
|
||||
|
||||
if (lsp_thread.joinable())
|
||||
lsp_thread.join();
|
||||
|
||||
|
||||
0
src/ruby/bindings.cc
Normal file → Executable file
0
src/ruby/bindings.cc
Normal file → Executable file
0
src/ruby/process.cc
Normal file → Executable file
0
src/ruby/process.cc
Normal file → Executable file
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user