reddit / emacs

Help with lsp-mode and javascript completion for imported files

ozzopp · 2022-04-14 07:48
Hi everyone, I've set up `lsp-mode`, `lsp-ui`, `lsp-ivy` and `company` to work on my javascript files. As LS I am using the theia-ide recommended one. In my working enviroment I use Mozilla Rhino as the js engine so the syntax may be sometimes different to the standard javascript. Unfortunatly there isn't a LS specifically designed for Rhino. Everything seems to work fine except for the completion of imported files. In Rhino the import statement for loading another js file is `load('/path/to/js/file')` and what I am missing in my workspace is completions and suggestions for variables, functions and other stuff defined other files different from the one I'm working on. (use-package lsp-mode :commands (lsp lsp-deferred) :init (setq lsp-keymap-prefix "C-c l" lsp-auto-guess-root t lsp-clients-typescript-npm-location "/usr/local/bin/npm") ;; tuning (setq gc-cons-threshold 100000000 read-process-output-max (* 1024 1024) lsp-idle-delay 0.5) :config (lsp-enable-which-key-integration t)) (use-package lsp-ui :hook (lsp-mode . lsp-ui-mode) :custom (lsp-ui-doc-position 'bottom)) (use-package lsp-ivy :hook (lsp-mode . lsp-ivy-mode)) (use-package company :after lsp-mode :hook (lsp-mode . company-mode) :bind (:map company-active-map ("<tab>" . company-complete-selection)) (:map lsp-mode-map ("<tab>" . company-indent-or-complete-common)) :custom (company-minimum-prefix-length 1) (company-idle-delay 0.0)) In addition I have also a minimal configuration for `js2-mode` that I'm leaving here. (use-package js2-mode :mode "\\.js\\'" :hook (js2-mode . lsp-deferred) :config (setq js2-basic-offset 2)) (use-package js2-refactor) (use-package xref-js2) If anything is unclear or needs more specification just tell me. Thank you in advance.
mauguro_ · 2022-04-14 14:10
I use theia server too, and didn't have any problems with file importing, to autocomplete functions/imports/states and that kind of stuff you could get a look into yasnippet, the only problem is that I still don't know how to properly have company to use lsp and yasnippet servers in the same "menu"
mauguro_ · 2022-04-14 14:23
here is my [config](https://github.com/AlanMauricioC/dot-files/blob/main/emacs/custom/config.org#yasnippet) if you want to take a look
ozzopp · 2022-04-14 14:24
Sorry but maybe I didn't explain myself correctly. The behaviour I'm searching is: in file A.js I define the function `foo()`, now in a file B.js (in the same project, both files loaded in the lsp workspace) I import the file A.js with the command `load('A.js');` that is Rhino specific. If in the file B while editing I type 'f' I want to get foo as a completion hint. Is this possibile?
mauguro_ · 2022-04-14 14:31
uhmmmm I think since you are importing files with `load('xx.js')` lsp won't recognize that the functions inside that file are being imported to that scope :/ I haven't heard about Rhino until now, I'll take a look:0