From 024fd444d673be63ac23fc83481a8fe624127cbf Mon Sep 17 00:00:00 2001 From: pommicket Date: Wed, 11 Jan 2023 23:15:10 -0500 Subject: LANG_TEXT, turn off phantom completions for text/cfg/md files --- base.h | 3 ++- buffer.c | 12 +++++++++--- lsp-write.c | 1 + syntax.c | 3 +++ ted.cfg | 12 ++++++++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/base.h b/base.h index 32229e0..a5e5299 100644 --- a/base.h +++ b/base.h @@ -183,7 +183,7 @@ static void print(const char *fmt, ...) { // If you are adding new languages, DO NOT change the constant values // of the previous languages. It will mess up config files which use :set-language! typedef enum { - LANG_NONE = 0, + LANG_NONE = 0, // avoid using this and use LANG_TEXT instead. LANG_C = 1, LANG_CPP = 2, LANG_RUST = 3, @@ -200,6 +200,7 @@ typedef enum { LANG_JSON = 14, LANG_XML = 15, LANG_GLSL = 16, + LANG_TEXT = 17, // plain text LANG_COUNT } Language; diff --git a/buffer.c b/buffer.c index c00d20b..605a418 100644 --- a/buffer.c +++ b/buffer.c @@ -218,7 +218,7 @@ static Font *buffer_font(TextBuffer *buffer) { // what programming language is this? Language buffer_language(TextBuffer *buffer) { if (!buffer->path) - return LANG_NONE; + return LANG_TEXT; // @TODO(optimization): cache this? // (we're calling buffer_lsp on every edit and that calls this) @@ -229,7 +229,7 @@ Language buffer_language(TextBuffer *buffer) { size_t filename_len = strlen(filename); int match_score = 0; - Language match = LANG_NONE; + Language match = LANG_TEXT; for (u16 l = 0; l < LANG_COUNT; ++l) { const char *extensions = settings->language_extensions[l]; @@ -2759,7 +2759,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { Language language = buffer_language(buffer); // dynamic array of character types, to be filled by syntax_highlight SyntaxCharType *char_types = NULL; - bool syntax_highlighting = language && settings->syntax_highlighting; + bool syntax_highlighting = language && language != LANG_TEXT && settings->syntax_highlighting; if (buffer->frame_latest_line_modified >= buffer->frame_earliest_line_modified && syntax_highlighting) { @@ -2991,6 +2991,8 @@ void buffer_dedent_cursor_line(TextBuffer *buffer) { void buffer_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { Language lang = buffer_language(buffer); const char *start = language_comment_start(lang), *end = language_comment_end(lang); + if (!start[0] && !end[0]) + return; String32 start32 = str32_from_utf8(start), end32 = str32_from_utf8(end); buffer_start_edit_chain(buffer); @@ -3044,6 +3046,8 @@ static bool buffer_line_ends_with_ascii(TextBuffer *buffer, u32 line_idx, const void buffer_uncomment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { Language lang = buffer_language(buffer); const char *start = language_comment_start(lang), *end = language_comment_end(lang); + if (!start[0] && !end[0]) + return; u32 start_len = (u32)strlen(start), end_len = (u32)strlen(end); buffer_start_edit_chain(buffer); for (u32 line_idx = first_line; line_idx <= last_line; ++line_idx) { @@ -3066,6 +3070,8 @@ void buffer_uncomment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { void buffer_toggle_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { Language lang = buffer_language(buffer); const char *start = language_comment_start(lang), *end = language_comment_end(lang); + if (!start[0] && !end[0]) + return; // if first line is a comment, uncomment lines, otherwise, comment lines if (buffer_line_starts_with_ascii(buffer, first_line, start) && buffer_line_ends_with_ascii(buffer, first_line, end)) diff --git a/lsp-write.c b/lsp-write.c index 19bd766..4409593 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -10,6 +10,7 @@ static const char *lsp_language_id(Language lang) { switch (lang) { case LANG_CONFIG: case LANG_TED_CFG: + case LANG_TEXT: case LANG_NONE: return "text"; case LANG_C: diff --git a/syntax.c b/syntax.c index 9b60d6a..0ff8ac9 100644 --- a/syntax.c +++ b/syntax.c @@ -88,6 +88,7 @@ static const LanguageName language_names[] = { {LANG_JSON, "JSON"}, {LANG_XML, "XML"}, {LANG_GLSL, "GLSL"}, + {LANG_TEXT, "Text"}, }; static_assert_if_possible(arr_count(language_names) == LANG_COUNT) @@ -135,6 +136,7 @@ const char *language_comment_start(Language l) { return "