Skip to content

Commit

Permalink
hover: remove :dylan:dylan from names in the dylan module
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
cgay committed Dec 18, 2024
1 parent dd19f86 commit 7a5fd09
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions sources/handlers.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,26 @@ define handler workspace/didChangeConfiguration
end;
end handler;

// TODO: make this configurable.
define constant *module-name-replacements*
= begin
let t = make(<string-table>);
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(<string>)) => (hover :: false-or(<string>))
if (txt)
let lines = split-lines(txt);
join(tail(lines), " ", key: strip);
end if;
(text :: <string>) => (hover :: <string>)
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
Expand All @@ -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
Expand Down

0 comments on commit 7a5fd09

Please sign in to comment.