diff options
author | pommicket <pommicket@gmail.com> | 2022-12-24 12:02:40 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-24 12:02:40 -0500 |
commit | a6a06900bf7206dc86017bbb1895272ebfac5418 (patch) | |
tree | 2f49cee6002d5d10bb4afc0db18425e5f5dfb38e /ted.c | |
parent | 1c346f2aba30fcb581f20f2b67bd5e6adcb4a7e6 (diff) |
start LSP setting
Diffstat (limited to 'ted.c')
-rw-r--r-- | ted.c | 37 |
1 files changed, 32 insertions, 5 deletions
@@ -78,14 +78,41 @@ Settings *ted_active_settings(Ted *ted) { return settings; } -LSP *ted_get_lsp(Ted *ted, const char *path, Language lang) { - for (int i = 0; i < TED_LSP_MAX; ++i) { +Settings *ted_get_settings(Ted *ted, const char *path, Language language) { + long best_score = 0; + Settings *settings = ted->default_settings; + arr_foreach_ptr(ted->all_settings, Settings, s) { + long score = context_score(path, language, &s->context); + if (score > best_score) { + best_score = score; + settings = s; + } + } + return settings; +} + +LSP *ted_get_lsp(Ted *ted, const char *path, Language language) { + int i; + for (i = 0; i < TED_LSP_MAX; ++i) { LSP *lsp = ted->lsps[i]; if (!lsp) break; - if (lsp->language != lang) continue; - if (!str_has_prefix(path, lsp->root_dir)) continue; - return lsp; + if (lsp->language != language) continue; + + // check if root matches up + const char *lsp_root = lsp->root_dir; + if (str_has_path_prefix(path, lsp_root)) + return lsp; } + if (i == TED_LSP_MAX) + return NULL; // why are there so many LSP open??? + Settings *settings = ted_get_settings(ted, path, language); + if (*settings->lsp) { + // start up this LSP + char *root_dir = settings_get_root_dir(settings, path); + ted->lsps[i] = lsp_create(root_dir, language, settings->lsp); + free(root_dir); + } + return NULL; } |