Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove :dylan:dylan from hover text #40

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ install_bin = $(DYLAN)/bin
app_name = dylan-lsp-server

build: sources/*.dylan sources/lsp-dylan.lid sources/server.lid
dylan build --unify $(app_name)
deft build --unify $(app_name)

install: build
mkdir -p $(install_bin)
Expand All @@ -17,7 +17,7 @@ install: build
fi

test: sources/*-tests.dylan sources/test-suite*.dylan sources/test-suite.lid
dylan build lsp-dylan-test-suite
deft build lsp-dylan-test-suite
if [[ -d "_build" ]]; then \
_build/bin/lsp-dylan-test-suite ; \
else \
Expand Down
8 changes: 4 additions & 4 deletions documentation/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Installation
created::

$ cd lsp-dylan
$ dylan update
$ deft update

4. Build the ``dylan-lsp-server`` binary. This will install the binary in
``${DYLAN}/bin``. If :envvar:`DYLAN` is not defined it defaults to
Expand All @@ -49,7 +49,7 @@ Installation

or just run these commands::

$ dylan build --unify dylan-lsp-server
$ deft build --unify dylan-lsp-server
$ cp _build/sbin/dylan-lsp-server /usr/local/bin/

5. Make sure ``dylan-lsp-server`` is on your :envvar:`PATH`.
Expand Down Expand Up @@ -77,11 +77,11 @@ derived from the full pathname to the :program:`dylan-compiler` executable,
which must be on your :envvar:`PATH`.

When you open each new file in your editor the LSP client may try to start a
new project if the file isn't part of the same :program:`dylan` workspace
new project if the file isn't part of the same :program:`deft` workspace
directory. If you want the client to use just one project, use a `multi-package
workspace <https://opendylan.org/package/deft/index.html#workspaces>`_.

.. note:: Always run ``dylan update`` and ``dylan build -a`` in your workspace
.. note:: Always run ``deft update`` and ``deft build -a`` in your workspace
**before** starting the LSP server, or :program:`dylan-lsp-server`
may not be able to open your project. (This requirement will be
removed in a future release.)
Expand Down
34 changes: 22 additions & 12 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 Expand Up @@ -214,10 +224,10 @@ define handler textDocument/didOpen
show-info(session, "Opened project %s", name);
elseif (name)
show-error(session, "Couldn't open project %=."
" Try running `dylan update` and `dylan build -a`.", name);
" Try running `deft update` and `deft build -a`.", name);
else
show-error(session, "Couldn't determine which project to open."
" Try running `dylan update` and `dylan build -a`.");
" Try running `deft update` and `deft build -a`.");
log-debug("textDocument/didOpen: No project found for %s", file);
end;
end if;
Expand Down
Loading