LSP server and emacs LSP client glue for eglot and lsp-mode #80
Reference in New Issue
Block a user
Delete Branch "pkulev/sex:feature/lsp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
sexccan index a unit without stopping at the first bad form.sex-lspserves that index over LSP.sex-lsp.elregisters the same server with lsp-mode and eglot.sex-mode.elstays the editing mode.@alex-eg, specs, realizations, and closure helpers are not indexed, as you have plans to rework them substantially.
Compiler
A long-running query resets the compiler before it reads.
reset-name-tables!clears the name, type, and tag tables and then the sums, ops, specs, and realizations thatreset-declarations!already cleared. Macros, the module caches, form locations, and closure tables are cleared too. One file is analyzed at a time. The prelude is still prepended, but those forms were never read from a file, sou8andƛenvdo not show up as the unit's names.sex-errorstill aborts, and the message is stillfile:line: textplus the same arguments. It also records a diagnostic first, and the condition carries asexmark so the catcher does not record it twice. Warnings go into that same list instead of stderr while a query is running. A normalsexcbuild is unchanged: the list is off, the first error still ends the process.Recovery is one toplevel form at a time.
process-reccatches only when diagnostics are being collected. The bad form adds nothing to the output. Later forms are still walked, so a function after(nope)is still indexed. There is no statement-level recovery.While walking, plain declarations are recorded:
fn, with the written prototype(fn name args ret)and the docstringvar, global or local, and parametersstruct,union,enumtypedefconstsum, plus each constructor as anfnA local's scope is the line range of the
fn,do,for,while,if,switch, orcasethat binds it. It is visible from its own line through the end of that range. Lookup takes the tightest range that contains the point. Same span: the later declaration wins, and a struct beats the typedef of the same name. A global has no range and is visible through the whole unit. Importedpubforms keep the defining file's location, so a jump lands in that file. Names containingƛ,ǂ, orːare dropped. A sum records itself and then suppresses the structs and typedefs it generates underneath.Locations are still
(file line end-line)on forms. The identifier under the cursor is taken from the buffer text.sexc --checkprints(diagnostics ...). Exit status is non-zero only when the file cannot be read. Semantic errors stay in the list and the process exits 0.sexc --symbolsprints the table.sexc --expand-lines=START:ENDemits C with statement#linedirectives and keeps the chunks whose Sex line falls in that inclusive range.STARTalone, or:, is the whole buffer.Server
sex-lspis a second program: it speaks LSP on stdio and calls the query in-process.Medea is used to work with json, that part publishes diagnostics, and answers hover, definition, completion, and document symbols.
sex/expandtakes a 1-based line range and returns the C. A change reanalyzes on a 150 ms quiet wait.file-selectis always given a timeout. Without one it does not wake, and the stdin port is unbuffered so a short message is not stuck behind a 1024-byte fill.clangd is off unless
--c-backend=clangd. It is not shown a translation of the buffer. The server forks it onto pipes and asks it about a probe: the unit's(include ...)forms, the prelude headers, andNAME(0)inside a function. Hyphens become underscores except in->. Results come back kebab-case. The probe sits for about a second and a half so clangd can read the headers before it answers. A half-typed name is completed. Hover and definition are requested on a finished name. Flags are a one-linesex-cflagsfile or--cflags.Emacs
sex-mode.eldefines sex-mode, syntax highlight and navigation,sex-lsp.eladds LSP on top.Test plan
bar(fn bar ((a int)) void)andAdd once.M-.on the callbarpub fn.M-,comes backC-M-iafter(babar(nope)inunknown top level form. lsp-mode:M-x flycheck-list-errorsM-x imenubar,main, and their parametersC-c C-eon a sexp,C-c C-don a defun,C-c C-ron a region,C-c C-bfor the buffer*sexpand*in a C mode, with the C for that rangesex-c-backendisclangd, then complete(priprintf(printf "hi")M-.opensstdio.h(priis only long enough for completion. Hover and definition need the whole name.make checkcovers the server side of hover, diagnostics, andsex/expand.ac6daa748etoe2f71d23a0View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.