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

Add instructions for emacs with lsp-mode #3647

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

alanz
Copy link

@alanz alanz commented Nov 30, 2022

Documentation change only

@stew
Copy link
Member

stew commented Nov 30, 2022

When I try to add this stuff to my emacs inititalization I get:

Symbol's function definition is void: lsp-register-client

@alanz
Copy link
Author

alanz commented Nov 30, 2022

lsp-register-client is defined in lsp-mode. I guess I should add

(use-package lsp-mode
)

@stew
Copy link
Member

stew commented Nov 30, 2022

Now when I open a .u file I get this message:

LSP :: The following servers support current file but do not have automatic installation: unisonlang
You may find the installation instructions at https://emacs-lsp.github.io/lsp-mode/page/languages.
(If you have already installed the server check *lsp-log*).

@alanz
Copy link
Author

alanz commented Nov 30, 2022

As per the overall language server instructions, you do not start it as normal, just connect to it.

So what I do is

M-x term
~/unisonlang/ucm

This starts a ucm session, which also listens on port 5757.

Then open a xxx.u file in the same directory you started ucm, and it should work. You can also do lsp-workspace-restart once you start up ucm

@stew
Copy link
Member

stew commented Nov 30, 2022

Yeah, I still get this error whenever it tries to start lsp-mode in a .u buffer. even if ucm is running.

lsp-mode DOES work for other language servers, and LSP is currently working for me with unison using vscode

@acowley
Copy link

acowley commented Jan 18, 2023

I ran into the same situation as stew when following the instructions in this PR.

The approach shown below works in that I see type check errors, but the type information for local variables is not good (e.g. for the Unison hello world program, the use of the local variable name shows popups for Author.name and CopyrightHolder.name). I also get The connected server(s) does not support method textDocument/completion. when trying to complete names. If those are all expected, I can open a PR with this approach (which I modeled on lsp-gdscript).

(lsp-register-client
   (make-lsp-client
    :language-id "unisonlang"
    :new-connection 
    (list
     :connect (lambda (filter sentinel name _environment-fn _workspace)
                (let* ((host "localhost")
                       (port 5757)
                       (tcp-proc (lsp--open-network-stream host port (concat name "::tcp"))))

                  (set-process-query-on-exit-flag tcp-proc nil)
                  (set-process-filter tcp-proc filter)
                  (set-process-sentinel tcp-proc sentinel)
                  (cons tcp-proc tcp-proc)))
     :test? (lambda () t))
    :major-modes '(unisonlang-mode)
    :server-id 'unisonlang
    ))

@zetashift
Copy link
Contributor

zetashift commented Feb 8, 2023

I don't see the textDocument/completion errors, but the type information for local variables indeed is off:
image

(my cursor is on the "name" variable)

My config:

(use-package unisonlang-mode
  :mode "\\.u\\'"
  :ensure t
  :config
  
  (add-hook 'unisonlang-mode-hook 'lsp-deferred)
  (with-eval-after-load 'lsp-mode
    (add-to-list 'lsp-language-id-configuration
         '(unisonlang-mode . "unisonlang"))
    (setq-local lsp-tcp-connection-timeout 10)
    (lsp-register-client
     (make-lsp-client
      :new-connection
      (list
       :connect (lambda (filter sentinel name _environment-fn _workspace)
                  (let* ((host "localhost")
             (port 5757)
             (tcp-proc (lsp--open-network-stream host port (concat name "::tcp"))))

                    (set-process-query-on-exit-flag tcp-proc nil)
                    (set-process-filter tcp-proc filter)
                    (set-process-sentinel tcp-proc sentinel)
                    (cons tcp-proc tcp-proc)))
       :test? (lambda () t))
      :activation-fn (lsp-activate-on "unisonlang")
      :server-id 'unisonlang))))

@zetashift
Copy link
Contributor

I don't know if this should be a new issue but VSCode reports the same actually:

image

@sellout
Copy link
Contributor

sellout commented May 8, 2024

I just put up #4922, which does this for Eglot instead of lsp-mode. Mostly because it’s simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants