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

Selecting a flutter project root breaks lsp #199

Open
rileyrg opened this issue Jul 23, 2023 · 1 comment
Open

Selecting a flutter project root breaks lsp #199

rileyrg opened this issue Jul 23, 2023 · 1 comment

Comments

@rileyrg
Copy link

rileyrg commented Jul 23, 2023

Emacs 29 built from source. Using straight package manager.

I documented the issue here : https://www.reddit.com/r/emacs/comments/156udd9/lsp_package_and_dartflutter_issues/?utm_source=share&utm_medium=android_app&utm_name=androidcss&utm_term=1&utm_content=1

In short, create a new flutter project , flutter create test, create .projectile in the new project root, open test/lib/main.dart . LSP prompts to import , hit "i". LSP and flycheck appear to be enabled but it doesn't work... No flycheck errors when you force an error, no LSP UI annotations.

If you set the project root as test/lib then it works BUT isn't really functional, as any packages added eg

flutter pub add flame

eg

import 'package:flame/game.dart';

fails.

If I set the root to the proper root (no lsp ui annotations or flycheck errors) completion of newly added libraries DOES work - indicating LSP is working from the root - so something weird.

Workaround : If I delete session.el I can set the import directory for to ROOT/lib when I start lsp, then I can add the ROOT directory as a workspace folder and then things seem to work so far BUT only after an emacs restart. Adding the flutter project root as a workspace doesnt make it work during the current session even if I disconnect lsp and restart. I need to restart emacs. Sounds dodgy I know, but its what I'm seeing.

As an addendum: eglot just works without prompting or needing to add additional workspaces indicating the error might be at the lsp package level rather than the dart analysis server. I'd prefer to use lsp because of its richer UI experience.

Pretty standard lsp setup.

https://github.com/rileyrg/Emacs-Customisations/blob/dev/etc/elisp/rgr-lsp.el


(use-package lsp-mode
  :init
  ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
  (setq lsp-keymap-prefix "C-l")
  :config
  (use-package lsp-ui :commands lsp-ui-mode)
  (use-package lsp-treemacs :commands lsp-treemacs-errors-list)
  (lsp-treemacs-sync-mode 1)
  (use-package flycheck)
  (use-package dap-mode)
  (use-package lsp-dart)
  (setq lsp-completion-provider :capf)
  ;; (defun corfu-lsp-setup ()
  ;;   (setq-local completion-styles '(orderless)
  ;;               completion-category-defaults nil))
  ;; (add-hook 'lsp-completion-mode-hook #'corfu-lsp-setup)

  :hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
         (lsp-mode . lsp-enable-which-key-integration))
  :commands (lsp lsp-deferred))

(use-package eglot
  :straight `(eglot ,@(when (>= emacs-major-version 29) '(:type built-in)))
  :config
  (use-package eldoc-box)
  :hook
  (prog-mode . eldoc-box-hover-at-point-mode)
  :bind
  (:map flymake-mode-map
        ([remap next-error] . flymake-goto-next-error)
        ([remap previous-error] . flymake-goto-prev-error))
  (:map eglot-mode-map
        ("<C-return>" . eglot-code-actions)))

(provide 'rgr/lsp)


@ericdallo
Copy link
Member

thanks, I intend to look at this soon

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

2 participants