diff options
author | pommicket <pommicket@gmail.com> | 2023-03-02 09:53:11 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-03-02 09:53:11 -0500 |
commit | 595cc50b7985ec67c49c6e2ffc649cb04692a318 (patch) | |
tree | 970ab71aadabc9f0f0a7a1634512c31aedd23188 /lsp-write.c | |
parent | 6d9ebc8332b6cc54ada4bc17689e4de4040892c6 (diff) |
dynamic language registration working
Diffstat (limited to 'lsp-write.c')
-rw-r--r-- | lsp-write.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/lsp-write.c b/lsp-write.c index 2689869..830c0ab 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -8,27 +8,19 @@ typedef struct { u64 number; - char identifier[32]; + char *identifier; } LanguageId; -static LanguageId language_ids[512]; +static LanguageId *language_ids = NULL; // dynamic array void lsp_register_language(u64 id, const char *lsp_identifier) { - int i; - for (i = 0; *language_ids[i].identifier; ++i) { - if (language_ids[i].number == id) { - break; - } - } - if (i < (int)arr_count(language_ids) - 1) { - language_ids[i].number = id; - strbuf_cpy(language_ids[i].identifier, lsp_identifier); - } + LanguageId *lid = arr_addp(language_ids); + lid->number = id; + lid->identifier = str_dup(lsp_identifier); } static const char *lsp_language_id(u64 lang) { - int i; - for (i = 0; *language_ids[i].identifier; ++i) { - if (language_ids[i].number == lang) { - return language_ids[i].identifier; + arr_foreach_ptr(language_ids, LanguageId, lid) { + if (lid->number == lang) { + return lid->identifier; } } assert(0); |