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

How can I use lsp completion without lsp--cur-workspace? #58

Open
stardiviner opened this issue Oct 2, 2018 · 8 comments
Open

How can I use lsp completion without lsp--cur-workspace? #58

stardiviner opened this issue Oct 2, 2018 · 8 comments

Comments

@stardiviner
Copy link

I want to get code completion in Org Mode source block. But lsp-mode/company-lsp requires lsp--cur-workspace. Is it possible to code completion without it?

@tigersoldier
Copy link
Owner

company-lsp doesn't work if you cannot run language server on the code.

IMO there can be solution to this - create a temporary buffer for the source block and run language server over the temporary file, pipe the result to the original buffer. However, this is beyond the scope of company-lsp. Maybe open a feature request to lsp-mode?

@yyoncho
Copy link
Contributor

yyoncho commented Oct 11, 2018

This is already fixed in lsp-mode emacs-lsp/lsp-mode#377 (comment)

@stardiviner
Copy link
Author

This is fixed in lsp-java. I try some other clients like lsp-python, lsp-javascript-typescript and lsp-php.

  • lsp-python works fine
  • lsp-javascript-typescript reports error: Warning (lsp-mode): Couldn’t find project root, using the current directory as the root. Don't know how to set lsp-mode project root.
  • lsp-php does not provide the completion. did not raise any error up.

@yyoncho
Copy link
Contributor

yyoncho commented Oct 23, 2018

To setup lsp-javascript-typescript you should have package.json in the root(similar to the java project where you have pom.xml somewhere in the root). Here it is the relevant code https://github.com/emacs-lsp/lsp-javascript/blob/ab62826962887e82f0bc968817be4fc89a6953e4/lsp-typescript.el#L54 . You should first setup the language server without org-mode and then configure org-mode to point to one of the files in the project.

@stardiviner
Copy link
Author

I decide to write a small package specially for handling this. I found Org Mode has a built-in header argument :file. I might use it in package. @yyoncho WDYT?

@yyoncho
Copy link
Contributor

yyoncho commented Oct 23, 2018

Sounds good to me. Make sure you do a reddit post after it is ready.

@stardiviner
Copy link
Author

The lsp--cur-workspace still is nil when I setup like this:

#+begin_src emacs-lisp :cache no
(defun org-babel-edit-prep:js (babel-info)
  "Prepare buffer local environment for Org source block Java."
  (setq-local buffer-file-name (->> babel-info
                                    caddr
                                    (alist-get :file)))
  (setq-local lsp-buffer-uri (->> babel-info
                                  caddr
                                  (alist-get :file)
                                  lsp--path-to-uri))
  (lsp-javascript-typescript-enable)
  )
#+end_src

#+begin_src js :file "~/Documents/learning/Web/JavaScript/react-demo/index.js"

#+end_src
(use-package lsp-javascript-typescript
  :ensure t
  :ensure-system-package (javascript-typescript-stdio . "npm i -g javascript-typescript-langserver")
  :init (require 'lsp-javascript-typescript)
  (add-hook 'js-mode-hook #'lsp-mode)
  (add-hook 'js-mode-hook #'lsp-javascript-typescript-enable)

  (add-hook 'js2-mode-hook #'lsp-mode)
  (add-hook 'js2-mode-hook #'lsp-javascript-typescript-enable)

  (add-hook 'js3-mode-hook #'lsp-mode)
  (add-hook 'js3-mode-hook #'lsp-javascript-typescript-enable) ;; for js3-mode support

  (add-hook 'typescript-mode-hook #'lsp-javascript-typescript-enable)
  (add-hook 'rjsx-mode #'lsp-javascript-typescript-enable) ;; for rjsx-mode support

  ;; Org Babel source block support
  ;; TODO:
  )

@yyoncho
Copy link
Contributor

yyoncho commented Mar 14, 2019

This bug is no longer relevant.

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

No branches or pull requests

3 participants