From 7a5fd0909705eacfcfc7304e37edce48bf00bd6b Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Wed, 18 Dec 2024 09:57:44 -0500 Subject: [PATCH] hover: remove :dylan:dylan from names in the dylan module This is quick and dirty because I don't want to get too side-tracked on LSP right now. Ultimately we need this to be configurable and/or to have a switch to elide all module names. (One can always find them with M-. if they're ambiguous.) --- sources/handlers.dylan | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/sources/handlers.dylan b/sources/handlers.dylan index b8a166a..d5d15a8 100644 --- a/sources/handlers.dylan +++ b/sources/handlers.dylan @@ -147,16 +147,26 @@ define handler workspace/didChangeConfiguration end; end handler; +// TODO: make this configurable. +define constant *module-name-replacements* + = begin + let t = make(); + t[":dylan:dylan"] := ""; + t + end; + // Format symbol description into a hover message. -// The description comes from the compiler database as a string with -// multiple lines - the first is a location which we don't need. -// Cut this and join the rest as one line. define function format-hover-message - (txt :: false-or()) => (hover :: false-or()) - if (txt) - let lines = split-lines(txt); - join(tail(lines), " ", key: strip); - end if; + (text :: ) => (hover :: ) + let lines = copy-sequence(split-lines(text), start: 1); // Remove source location info. + let msg = join(lines, " ", key: strip); + for (want keyed-by got in *module-name-replacements*) + let pos = #f; + while (pos := subsequence-position(msg, got)) + msg := replace-subsequence!(msg, want, start: pos, end: pos + got.size); + end; + end; + msg end function; // Show information about a symbol when we hover the cursor over it @@ -175,8 +185,8 @@ define handler textDocument/hover let symbol = module & symbol-at-position(doc, line, column); let hover = if (symbol) let txt = describe-symbol(symbol, module: module); - let msg = format-hover-message(txt); - if (msg) + if (txt) + let msg = format-hover-message(txt); json("contents", make-lsp-markup-content(msg, markdown?: #f)); end; else