Allow ruby based configs and custom syntax parsers
This commit is contained in:
291
include/config.h
291
include/config.h
@@ -1,291 +0,0 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include "lsp/lsp.h"
|
||||
#include "pch.h"
|
||||
|
||||
static const std::unordered_map<uint8_t, LSP> kLsps = {
|
||||
{1,
|
||||
{"clangd",
|
||||
{
|
||||
"clangd",
|
||||
"--background-index",
|
||||
"--clang-tidy",
|
||||
"--completion-style=detailed",
|
||||
"--header-insertion=never",
|
||||
"--pch-storage=memory",
|
||||
"--limit-results=50",
|
||||
"--log=error",
|
||||
nullptr,
|
||||
}}},
|
||||
{2,
|
||||
{"ruby-lsp",
|
||||
{
|
||||
"ruby-lsp",
|
||||
nullptr,
|
||||
}}},
|
||||
{3,
|
||||
{"solargraph",
|
||||
{
|
||||
"solargraph",
|
||||
"stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
{4,
|
||||
{"bash-language-server",
|
||||
{
|
||||
"bash-language-server",
|
||||
"start",
|
||||
nullptr,
|
||||
}}},
|
||||
{5,
|
||||
{"vscode-css-language-server",
|
||||
{
|
||||
"vscode-css-language-server",
|
||||
"--stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
{6,
|
||||
{"vscode-json-language-server",
|
||||
{
|
||||
"vscode-json-language-server",
|
||||
"--stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
{7,
|
||||
{"fish-lsp",
|
||||
{
|
||||
"fish-lsp",
|
||||
"start",
|
||||
nullptr,
|
||||
}}},
|
||||
{8,
|
||||
{"gopls",
|
||||
{
|
||||
"gopls",
|
||||
"serve",
|
||||
nullptr,
|
||||
}}},
|
||||
{9,
|
||||
{"haskell-language-server",
|
||||
{
|
||||
"haskell-language-server",
|
||||
"lsp",
|
||||
nullptr,
|
||||
}}},
|
||||
{10,
|
||||
{"emmet-language-server",
|
||||
{
|
||||
"emmet-language-server",
|
||||
"--stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
{11,
|
||||
{"typescript-language-server",
|
||||
{
|
||||
"typescript-language-server",
|
||||
"--stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
#define LUA_LS 12
|
||||
{12,
|
||||
{"lua-language-server",
|
||||
{
|
||||
"lua-language-server",
|
||||
nullptr,
|
||||
}}},
|
||||
{13,
|
||||
{"pyright-langserver",
|
||||
{
|
||||
"pyright-langserver",
|
||||
"--stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
{14,
|
||||
{"rust-analyzer",
|
||||
{
|
||||
"rust-analyzer",
|
||||
nullptr,
|
||||
}}},
|
||||
{15,
|
||||
{"intelephense",
|
||||
{
|
||||
"intelephense",
|
||||
"--stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
{16,
|
||||
{"marksman",
|
||||
{
|
||||
"marksman",
|
||||
"server",
|
||||
nullptr,
|
||||
}}},
|
||||
{17,
|
||||
{"nginx-language-server",
|
||||
{
|
||||
"nginx-language-server",
|
||||
nullptr,
|
||||
}}},
|
||||
{18,
|
||||
{"taplo",
|
||||
{
|
||||
"taplo",
|
||||
"lsp",
|
||||
"stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
{19,
|
||||
{"yaml-language-server",
|
||||
{
|
||||
"yaml-language-server",
|
||||
"--stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
{20,
|
||||
{"sqls",
|
||||
{
|
||||
"sqls",
|
||||
"serve",
|
||||
nullptr,
|
||||
}}},
|
||||
{21,
|
||||
{"make-language-server",
|
||||
{
|
||||
"make-language-server",
|
||||
nullptr,
|
||||
}}},
|
||||
{22,
|
||||
{"sql-language-server",
|
||||
{
|
||||
"sql-language-server",
|
||||
"up",
|
||||
"--method",
|
||||
"stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, Language> kLanguages = {
|
||||
{"bash", {"bash", 4, 0x4d5a5e, " "}},
|
||||
{"c", {"c", 1, 0x555555, " "}},
|
||||
{"cpp", {"cpp", 1, 0x00599C, " "}},
|
||||
{"h", {"h", 1, 0xA8B9CC, " "}},
|
||||
{"css", {"css", 5, 0x36a3d9, " "}},
|
||||
{"fish", {"fish", 7, 0x4d5a5e, " "}},
|
||||
{"go", {"go", 8, 0x00add8, " "}},
|
||||
{"gomod", {"gomod", 8, 0x00add8, " "}},
|
||||
{"haskell", {"haskell", 9, 0xa074c4, " "}},
|
||||
{"html", {"html", 10, 0xef8a91, " "}},
|
||||
{"javascript", {"javascript", 11, 0xf0df8a, " "}},
|
||||
{"typescript", {"typescript", 11, 0x36a3d9, " "}},
|
||||
{"json", {"json", 6, 0xcbcb41, "{}"}},
|
||||
{"jsonc", {"jsonc", 6, 0xcbcb41, "{}"}},
|
||||
{"erb", {"erb", 10, 0x6e1516, " "}},
|
||||
{"ruby", {"ruby", 3, 0xff8087, " "}},
|
||||
{"lua", {"lua", 12, 0x36a3d9, " "}},
|
||||
{"python", {"python", 13, 0x95e6cb, " "}},
|
||||
{"rust", {"rust", 14, 0xdea584, " "}},
|
||||
{"php", {"php", 15, 0xa074c4, " "}},
|
||||
{"markdown", {"markdown", 16, 0x36a3d9, " "}},
|
||||
{"markdown_inline", {"markdown_inline", 16, 0x36a3d9, " "}},
|
||||
{"nginx", {"nginx", 17, 0x6d8086, " "}},
|
||||
{"toml", {"toml", 18, 0x36a3d9, " "}},
|
||||
{"yaml", {"yaml", 19, 0x6d8086, " "}},
|
||||
{"sql", {"sql", 20, 0xdad8d8, " "}},
|
||||
{"make", {"make", 21, 0x4e5c61, " "}},
|
||||
{"gdscript", {"gdscript", 0, 0x6d8086, " "}},
|
||||
{"man", {"man", 0, 0xdad8d8, " "}},
|
||||
{"diff", {"diff", 0, 0xDD4C35, " "}},
|
||||
{"gitattributes", {"gitattributes", 0, 0xF05032, " "}},
|
||||
{"gitignore", {"gitignore", 0, 0xF05032, " "}},
|
||||
{"query", {"query", 0, 0x7E57C2, " "}},
|
||||
{"regex", {"regex", 0, 0x9E9E9E, ".*"}},
|
||||
{"ini", {"ini", 0, 0x6d8086, " "}},
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, std::string> kExtToLang = {
|
||||
{"sh", "bash"},
|
||||
{"bash", "bash"},
|
||||
{"c", "c"},
|
||||
{"cpp", "cpp"},
|
||||
{"cxx", "cpp"},
|
||||
{"cc", "cpp"},
|
||||
{"hpp", "h"},
|
||||
{"hh", "h"},
|
||||
{"hxx", "h"},
|
||||
{"h", "h"},
|
||||
{"css", "css"},
|
||||
{"fish", "fish"},
|
||||
{"go", "go"},
|
||||
{"hs", "haskell"},
|
||||
{"html", "html"},
|
||||
{"htm", "html"},
|
||||
{"js", "javascript"},
|
||||
{"jsx", "javascript"},
|
||||
{"ts", "typescript"},
|
||||
{"tsx", "typescript"},
|
||||
{"json", "json"},
|
||||
{"jsonc", "jsonc"},
|
||||
{"lua", "lua"},
|
||||
{"make", "make"},
|
||||
{"mk", "make"},
|
||||
{"makefile", "make"},
|
||||
{"man", "man"},
|
||||
{"py", "python"},
|
||||
{"rb", "ruby"},
|
||||
{"rs", "rust"},
|
||||
{"diff", "diff"},
|
||||
{"patch", "diff"},
|
||||
{"erb", "erb"},
|
||||
{"gd", "gdscript"},
|
||||
{"gitattributes", "gitattributes"},
|
||||
{"gitignore", "gitignore"},
|
||||
{"mod", "gomod"},
|
||||
{"ini", "ini"},
|
||||
{"gitmodules", "ini"},
|
||||
{"md", "markdown"},
|
||||
{"markdown", "markdown"},
|
||||
{"conf", "nginx"},
|
||||
{"php", "php"},
|
||||
{"scm", "query"},
|
||||
{"regex", "regex"},
|
||||
{"sql", "sql"},
|
||||
{"toml", "toml"},
|
||||
{"yaml", "yaml"},
|
||||
{"yml", "yaml"},
|
||||
{"clangd", "yaml"},
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, std::string> kMimeToLang = {
|
||||
{"text/x-c", "c"},
|
||||
{"text/x-c++", "cpp"},
|
||||
{"text/x-shellscript", "bash"},
|
||||
{"application/json", "json"},
|
||||
{"text/javascript", "javascript"},
|
||||
{"text/html", "html"},
|
||||
{"text/css", "css"},
|
||||
{"text/x-python", "python"},
|
||||
{"text/x-ruby", "ruby"},
|
||||
{"text/x-go", "go"},
|
||||
{"text/x-haskell", "haskell"},
|
||||
{"text/x-rust", "rust"},
|
||||
{"text/x-lua", "lua"},
|
||||
{"text/x-diff", "diff"},
|
||||
{"text/x-gdscript", "gdscript"},
|
||||
{"text/x-gitattributes", "gitattributes"},
|
||||
{"text/x-gitignore", "gitignore"},
|
||||
{"text/x-gomod", "gomod"},
|
||||
{"text/x-ini", "ini"},
|
||||
{"text/markdown", "markdown"},
|
||||
{"text/x-nginx-conf", "nginx"},
|
||||
{"application/x-php", "php"},
|
||||
{"text/x-tree-sitter-query", "query"},
|
||||
{"text/x-regex", "regex"},
|
||||
{"text/x-sql", "sql"},
|
||||
{"text/x-toml", "toml"},
|
||||
{"text/x-yaml", "yaml"},
|
||||
{"text/x-man", "man"},
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -30,6 +30,7 @@ struct Editor {
|
||||
uint32_t cursor_preffered;
|
||||
Coord selection;
|
||||
bool selection_active;
|
||||
bool unix_eol; // false for windows
|
||||
int selection_type;
|
||||
Coord position;
|
||||
Coord size;
|
||||
@@ -55,7 +56,8 @@ struct Editor {
|
||||
bool is_css_color;
|
||||
};
|
||||
|
||||
Editor *new_editor(const char *filename_arg, Coord position, Coord size);
|
||||
Editor *new_editor(const char *filename_arg, Coord position, Coord size,
|
||||
bool unix_eol);
|
||||
void save_file(Editor *editor);
|
||||
void free_editor(Editor *editor);
|
||||
void render_editor(Editor *editor);
|
||||
|
||||
@@ -5,11 +5,6 @@
|
||||
#include "pch.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
struct LSP {
|
||||
const char *command;
|
||||
std::vector<const char *> args;
|
||||
};
|
||||
|
||||
struct LSPPending {
|
||||
std::string method;
|
||||
Editor *editor = nullptr;
|
||||
@@ -50,7 +45,8 @@ struct LSPInstance {
|
||||
};
|
||||
|
||||
extern std::shared_mutex active_lsps_mtx;
|
||||
extern std::unordered_map<uint8_t, std::shared_ptr<LSPInstance>> active_lsps;
|
||||
extern std::unordered_map<std::string, std::shared_ptr<LSPInstance>>
|
||||
active_lsps;
|
||||
extern Queue<LSPOpenRequest> lsp_open_queue;
|
||||
|
||||
static json client_capabilities = {
|
||||
@@ -81,9 +77,9 @@ void lsp_send(std::shared_ptr<LSPInstance> lsp, json message,
|
||||
LSPPending *pending);
|
||||
void lsp_worker();
|
||||
|
||||
std::shared_ptr<LSPInstance> get_or_init_lsp(uint8_t lsp_id);
|
||||
void clean_lsp(std::shared_ptr<LSPInstance> lsp, uint8_t lsp_id);
|
||||
void close_lsp(uint8_t lsp_id);
|
||||
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);
|
||||
|
||||
void open_editor(std::shared_ptr<LSPInstance> lsp,
|
||||
std::pair<Language, Editor *> entry);
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#define PCRE_WORKSPACE_SIZE 512
|
||||
|
||||
#include "ruby.h"
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#include <ruby.h>
|
||||
#pragma clang diagnostic pop
|
||||
#include <magic.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <pcre2.h>
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
#ifndef SCRIPTING_DECL_H
|
||||
#define SCRIPTING_DECL_H
|
||||
|
||||
#include "syntax/decl.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
extern std::unordered_map<std::string, std::pair<VALUE, VALUE>>
|
||||
custom_highlighters;
|
||||
|
||||
void ruby_start(const char *main_file);
|
||||
void ruby_shutdown();
|
||||
void ruby_log(std::string msg);
|
||||
void load_theme();
|
||||
std::string read_line_endings();
|
||||
std::string read_utf_mode();
|
||||
void load_languages_info();
|
||||
bool read_line_endings();
|
||||
void load_custom_highlighters();
|
||||
VALUE parse_custom(std::vector<Token> *tokens, VALUE parser_block,
|
||||
const char *line, uint32_t len, VALUE state);
|
||||
bool custom_compare(VALUE match_block, VALUE state1, VALUE state2);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,4 +40,10 @@ struct LineData {
|
||||
std::shared_ptr<void> out_state{nullptr};
|
||||
};
|
||||
|
||||
struct CustomState {
|
||||
VALUE state;
|
||||
CustomState(VALUE s) : state(s) { rb_gc_register_address(&state); }
|
||||
~CustomState() { rb_gc_unregister_address(&state); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef SYNTAX_PARSER_H
|
||||
#define SYNTAX_PARSER_H
|
||||
|
||||
#include "scripting/decl.h"
|
||||
#include "syntax/decl.h"
|
||||
#include "syntax/line_tree.h"
|
||||
|
||||
@@ -12,11 +13,15 @@ struct Parser {
|
||||
const char *text, uint32_t len);
|
||||
bool (*state_match_func)(std::shared_ptr<void> state_1,
|
||||
std::shared_ptr<void> state_2);
|
||||
VALUE parser_block = Qnil;
|
||||
VALUE match_block = Qnil;
|
||||
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;
|
||||
std::set<uint32_t> dirty_lines;
|
||||
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);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// When updating this file with new types do not forget to update libcrib.rb to parallel changes
|
||||
ADD(K_DATA)
|
||||
ADD(K_SHEBANG)
|
||||
ADD(K_COMMENT)
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
#include "pch.h"
|
||||
|
||||
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);
|
||||
@@ -32,6 +29,49 @@ template <typename T> struct Queue {
|
||||
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 {
|
||||
@@ -60,11 +100,21 @@ struct Match {
|
||||
|
||||
struct Language {
|
||||
std::string name;
|
||||
uint8_t lsp_id;
|
||||
std::string lsp_name;
|
||||
uint32_t color;
|
||||
const char *symbol;
|
||||
std::string symbol;
|
||||
};
|
||||
|
||||
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, std::string> language_mimetypes;
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user