Skip to content

Commit

Permalink
Merge pull request #40 from cgay/dev
Browse files Browse the repository at this point in the history
Remove :dylan:dylan from hover text
  • Loading branch information
cgay authored Dec 18, 2024
2 parents 1915a33 + 365446f commit 896c61c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
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

0 comments on commit 896c61c

Please sign in to comment.