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

Weird output when adding overrides via lsp #198

Open
laynor opened this issue Jul 5, 2023 · 2 comments
Open

Weird output when adding overrides via lsp #198

laynor opened this issue Jul 5, 2023 · 2 comments

Comments

@laynor
Copy link

laynor commented Jul 5, 2023

Describe the bug

As requested, opening a new issue

When I create a simple widget class

class Foo extends StatelessWidget {
}

and then invoke lsp-execute-code-action with the cursor on Foo and select create missing override I get this weird output:

class Foo extends StatelessWidget {
  @override
  Widget build(1|BuildContext,Object| context) {
    // TODO: implement build
    throw UnimplementedError();
  }
}

To Reproduce
{populate}

Expected behavior

class Foo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    throw UnimplementedError();
  }
}

Version
Include here the result of: M-x lsp-dart-version

[LSP Dart] 1.24.2 at 2023.07.05 @ Emacs 30.0.50
[Dart SDK] Dart SDK version: 3.0.5 (stable) (Mon Jun 12 18:31:49 2023 +0000) on "linux_x64"

[Flutter SDK] /home/ale/src/3rdparty/flutter
[Flutter project] true
[Project entrypoint] Not found

@laynor
Copy link
Author

laynor commented Jul 5, 2023

As a workaround, I'm using the following:

(defun my/lsp--apply-workspace-edit-advice-dart (orig workspace-edit &rest args)
  (let ((document-changes (gethash "documentChanges" workspace-edit)))
    (mapc
     (lambda (dc-ht)
       (let* ((edits (gethash "edits" dc-ht)))
         (mapc (lambda (ht)
                 (let* ((new-text (gethash "newText" ht))
                        (filtered (if (eq major-mode 'dart-mode)
                                      (my/filter-snippet-for-dart new-text)
                                    new-text)))
                   (puthash "newText" filtered ht))
                 )
               edits)))
     document-changes))
  (apply orig workspace-edit args))

(defun advice-unadvice (sym)
  "Remove all advices from symbol SYM."
  (interactive "aFunction symbol: ")
  (advice-mapc (lambda (advice _props) (advice-remove sym advice)) sym))

(advice-add 'lsp--apply-workspace-edit :around #'my/lsp--apply-workspace-edit-advice-dart)

@ericdallo
Copy link
Member

@yyoncho do you think this fix ☝🏻 should go to lsp-mode?

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