summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-24 13:59:43 -0500
committerpommicket <pommicket@gmail.com>2022-12-24 13:59:43 -0500
commit1793fa40528295306d1d790074fdd8f382e8bef3 (patch)
tree2acc72e0ff15c0c66e478ea88bce4039f89d0b0a
parenta68d59e180b8131197c6387a764a78403b06e069 (diff)
testing LSPs for other languages
-rw-r--r--README.md69
-rw-r--r--base.h3
-rw-r--r--lsp.c2
-rw-r--r--lsp.h9
-rw-r--r--main.c15
-rw-r--r--ted.cfg24
6 files changed, 103 insertions, 19 deletions
diff --git a/README.md b/README.md
index 07b6850..3f00f1b 100644
--- a/README.md
+++ b/README.md
@@ -101,15 +101,72 @@ the current directory or one of its parents, depending on where `Makefile` is. O
If a `Cargo.toml` file exists in this directory or one of its parents, F4 will run `cargo build`. You can set the default build command
in the `[core]` section of the config file.
-Jump to definition and autocompletion both depend on [ctags](https://github.com/universal-ctags/ctags). You can press Ctrl+T
-at any time to generate or re-generate tags. Once you have a tags file, you can Ctrl+Click on an identifier
-to go to its definition. You can also press Ctrl+D to get a searchable list of all functions/types where you can select one to go to
-its definition.
+## LSP support
+
+ted has support for [LSPs](https://microsoft.github.io/language-server-protocol/)!
+
+
+You can Ctrl+Click on an identifier to go to its definition.
+You can also press Ctrl+D to get a searchable list of all functions/types where you can select one to go to
+its definition.
Press Ctrl+space to autocomplete. If there is only one possible completion from the tags file, it will be selected automatically.
Otherwise, you'll get a popup showing all possible completions. You can press tab to select a completion (or click on it), and press
-Ctrl+space/Ctrl+shift+space to cycle between suggestions. Note that autocomplete just completes to stuff in the tags file, so it won't complete local
-variable names. Sorry.
+Ctrl+space/Ctrl+shift+space to cycle between suggestions.
+
+If these features aren't working properly and you don't know why, try running ted in a terminal (non-Windows) or a debugger (Windows)
+so you can see the stderr output from the server.
+
+You can integrate any LSP server with ted by setting the `lsp` option in the `[core.<language>]` section of `ted.cfg`
+to the command which starts the server. Some defaults will already be there, and are listed below. Make
+sure you install the LSP(s) you want and put the executables in your PATH (or change the `lsp` variable
+to include the absolute path if not).
+
+### C/C++
+
+[clangd](https://clangd.llvm.org/installation)
+is enabled by default. On Debian/Ubuntu you can install it with:
+
+```
+sudo apt install clangd-15 # replace 15 with the highest number you can get
+sudo ln -s /usr/bin/clangd-15 /usr/bin/clangd
+```
+
+### Go
+
+The Go team's `go-pls` is enabled by default. You can download it
+[here](https://github.com/golang/tools/tree/master/gopls).
+
+
+## Java
+
+Eclipse's `jdtls` is enabled by default.
+You can download it [here](download.eclipse.org/jdtls/milestones/?d).
+
+## LaTeX
+
+`texlab` is enabled by default. You can download it
+[here](https://github.com/latex-lsp/texlab).
+
+### Python
+`python-lsp-server` is enabled by default.
+You can download it [here](https://github.com/python-lsp/python-lsp-server).
+
+### Rust
+
+`rust-analyzer` is enabled by default. You can download it
+by following [the instructions here](https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary).
+
+
+
+## Tags (lightweight LSP alternative)
+
+If an LSP is too much for you, you can also use [ctags](https://github.com/universal-ctags/ctags)
+for autocompletion and jump to definition. You can press Ctrl+T
+at any time to generate or re-generate tags.
+Ctrl+Click (go to definition), Ctrl+D (see all definitions), and autocomplete are all supported.
+Autocomplete will just complete to stuff in the tags file, so it won't complete local
+variable names for example.
## Building from source
diff --git a/base.h b/base.h
index 5ba03bc..26e874e 100644
--- a/base.h
+++ b/base.h
@@ -159,10 +159,13 @@ static void print(char const *fmt, ...) {
va_end(args);
OutputDebugStringA(buf);
}
+#define eprint print
#else
#define print printf
+#define eprint(...) fprintf(stderr, __VA_ARGS__)
#endif
#define println(...) print(__VA_ARGS__), print("\n")
+#define eprintln(...) eprint(__VA_ARGS__), eprint("\n")
#if DEBUG
#define debug_print print
diff --git a/lsp.c b/lsp.c
index 3b91705..2598144 100644
--- a/lsp.c
+++ b/lsp.c
@@ -146,7 +146,7 @@ static void lsp_receive(LSP *lsp, size_t max_size) {
if (nstderr > 0) {
// uh oh
stderr_buf[nstderr] = '\0';
- fprintf(stderr, "\x1b[1m\x1b[93m%s\x1b[0m", stderr_buf);
+ eprint("\x1b[1m\x1b[93m%s\x1b[0m", stderr_buf);
} else {
break;
}
diff --git a/lsp.h b/lsp.h
index 8383191..d68456a 100644
--- a/lsp.h
+++ b/lsp.h
@@ -1,12 +1,3 @@
-// @TODO:
-// - use document IDs instead of strings (also lets us use real document version numbers)
-// - document this and lsp.c.
-// - deal with "Save as" (generate didOpen)
-// - maximum queue size for requests/responses just in case?
-// - delete old sent requests
-// (if the server never sends a response)
-// - TESTING: make rust-analyzer-slow (waits 10s before sending response)
-
typedef u32 LSPDocumentID;
typedef enum {
diff --git a/main.c b/main.c
index 422b528..fb2265a 100644
--- a/main.c
+++ b/main.c
@@ -1,10 +1,21 @@
/*
@TODO:
+- in texlab, when typing "\something" why does the autocomplete menu close on 's'?
+ - is the weird documentation really what we're getting?
+- in jdtls, opening an empty java file gives an exception. is this my fault?
+- what's wrong with pylsp (try "f.w") in generate.py
+- what's wrong with gopls?
- make sure "save as" works
-- workspaceFolders support (so we don't need to start up multiple instances of rust-analyzer)
- more LSP stuff:
+ - hover
- go to definition using LSP
- find usages
+- workspaceFolders support (so we don't need to start up multiple instances of rust-analyzer)
+- document lsp.h and lsp.c.
+- maximum queue size for requests/responses just in case?
+- delete old sent requests? but make sure requests that just take a long time are okay.
+ (if the server never sends a response)
+- TESTING: make rust-analyzer-slow (waits 10s before sending response)
- rename buffer->filename to buffer->path
- make buffer->path NULL for untitled buffers & fix resulting mess
- run everything through valgrind ideally with leak checking
@@ -634,7 +645,7 @@ int main(int argc, char **argv) {
| (u32)shift_down << KEY_MODIFIER_SHIFT_BIT
| (u32)alt_down << KEY_MODIFIER_ALT_BIT;
ted->key_modifier = key_modifier;
-
+
while (SDL_PollEvent(&event)) {
TextBuffer *buffer = ted->active_buffer;
diff --git a/ted.cfg b/ted.cfg
index f10f4b0..249dcb2 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -70,9 +70,27 @@ root-identifiers = .ted-root.out, Cargo.toml, make.bat, CMakeLists.txt, Makefile
# bg-texture = "/path/to/my/cool/picture.jpg" (or .png, .gif, .bmp)
# bg-shader = "void main() { gl_FragColor = texture2D(t_texture, t_pos) * vec4(1.0,1.0,1.0,0.2); }"
+[C.core]
+lsp = "clangd --log=error"
+
+[C++.core]
+lsp = "clangd --log=error"
+
+[Go.core]
+lsp = "gopls"
+
+[Java.core]
+lsp = "jdtls"
+
+[Python.core]
+lsp = "pylsp"
+
[Rust.core]
lsp = "rust-analyzer"
+[Tex.core]
+lsp = "texlab"
+
[keyboard]
# motion and selection
Left = :left
@@ -149,7 +167,11 @@ Ctrl+Shift+r = :reload-all
# 5 TeX
# 6 Markdown
# 7 HTML
-# 8 Config (e.g. ted.cfg)
+# 8 Config
+# 9 JavaScript
+# 10 Java
+# 11 Go
+# 12 ted.cfg
# -1 Guess from the file extension (default)
Ctrl+Space = :autocomplete