castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.9k stars 157 forks source link

String interpolation completion doesn't work in certain situation #640

Open twlz0ne opened 1 year ago

twlz0ne commented 1 year ago

Steps to reproduce

  1. Create an empty project
$ mkdir test_rb
$ cd test_rb && git init
  1. Start emacs with following configuration:
$ emacs -Q --eval "\
(progn
   ;; elpa
   (require 'seq)
   (setq user-emacs-directory
         (car (seq-filter
               #'file-exists-p
               (list (format \"~/.emacs.d/%s/\" emacs-version)
                     (format \"~/.emacs.d/%s.%s/\" emacs-major-version emacs-minor-version)
                     \"~/.emacs.d/\"))))
   (setq package-user-dir (concat user-emacs-directory \"elpa/\"))
   (package-initialize)
   ;; config
   (require 'company)
   (global-company-mode)
   (setq company-backends '(company-capf)) ;; Inhibit word completion
   (require 'eglot)
   (add-hook 'ruby-mode-hook #'eglot-ensure))" ./test.rb
  1. Edit file (| represent the cursor)
...
name1="foo"
name2="bar"
puts "hello, #{na|}"
  1. Type m to trigger completion

Actual behaviour

Complete nothing.

Expect behaviour

Complete variables.

Enviroment

eglot logs

[client-notification] Wed Mar 15 14:19:58 2023:
(:jsonrpc "2.0" :method "textDocument/didChange" :params
          (:textDocument
           (:uri "file:///Users/*/Downloads/test_rb/test.rb" :version 18)
           :contentChanges
           [(:range
             (:start
              (:line 11 :character 17)
              :end
              (:line 11 :character 17))
             :rangeLength 0 :text "m")]))
[client-request] (id:68) Wed Mar 15 14:19:58 2023:
(:jsonrpc "2.0" :id 68 :method "textDocument/completion" :params
          (:textDocument
           (:uri "file:///Users/*/Downloads/test_rb/test.rb")
           :position
           (:line 11 :character 18)
           :context
           (:triggerKind 1)))
[server-reply] (id:68) Wed Mar 15 14:19:58 2023:
(:jsonrpc "2.0" :id 68 :result
          (:isIncomplete :json-false :items
                         [])) <<---- empty
twlz0ne commented 1 year ago

But if there is a space after the cursor or any character after the } completion will work, for example:

puts "hello, #{na| }"
# or
puts "hello, #{na|}a"

image

eglot logs:

[client-notification] Wed Mar 15 14:15:06 2023:
(:jsonrpc "2.0" :method "textDocument/didChange" :params
          (:textDocument
           (:uri "file:///Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb" :version 15)
           :contentChanges
           [(:range
             (:start
              (:line 11 :character 17)
              :end
              (:line 11 :character 17))
             :rangeLength 0 :text "m")]))
[client-request] (id:54) Wed Mar 15 14:15:06 2023:
(:jsonrpc "2.0" :id 54 :method "textDocument/completion" :params
          (:textDocument
           (:uri "file:///Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb")
           :position
           (:line 11 :character 18)
           :context
           (:triggerKind 1)))
[server-reply] (id:54) Wed Mar 15 14:15:06 2023:
(:jsonrpc "2.0" :id 54 :result
          (:isIncomplete :json-false :items
                         [(:label "name1" :kind 6 :detail nil :data
                                  (:path nil :return_type "undefined" :location
                                         (:filename "/Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb" :range
                                                    (:start
                                                     (:line 9 :character 0)
                                                     :end
                                                     (:line 9 :character 11)))
                                         :deprecated :json-false :uri "file:///Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb")
                                  :textEdit
                                  (:range
                                   (:start
                                    (:line 11 :character 15)
                                    :end
                                    (:line 11 :character 18))
                                   :newText "name1")
                                  :sortText "0000name1")
                          (:label "name2" :kind 6 :detail nil :data
                                  (:path nil :return_type "undefined" :location
                                         (:filename "/Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb" :range
                                                    (:start
                                                     (:line 10 :character 0)
                                                     :end
                                                     (:line 10 :character 11)))
                                         :deprecated :json-false :uri "file:///Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb")
                                  :textEdit
                                  (:range
                                   (:start
                                    (:line 11 :character 15)
                                    :end
                                    (:line 11 :character 18))
                                   :newText "name2")
                                  :sortText "0000name2")
                          (:label "NameError" :kind 7 :detail "=> Class<NameError>" :data
                                  (:path "NameError" :return_type "Class<NameError>" :location nil :deprecated :json-false :uri "file:///Volumes/HDD/Users/gqj/Downloads/test_rb/tes\
t_dict.rb")
                                  :textEdit
                                  (:range
                                   (:start
                                    (:line 11 :character 15)
                                    :end
                                    (:line 11 :character 18))
                                   :newText "NameError")
                                  :sortText "0001NameError")]))
[client-request] (id:55) Wed Mar 15 14:15:06 2023:
(:jsonrpc "2.0" :id 55 :method "completionItem/resolve" :params
          (:label
           #("name1" 0 1
             (eglot--lsp-item #1))
           :kind 6 :detail nil :data
           (:path nil :return_type "undefined" :location
                  (:filename "/Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb" :range
                             (:start
                              (:line 9 :character 0)
                              :end
                              (:line 9 :character 11)))
                  :deprecated :json-false :uri "file:///Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb")
           :textEdit
           (:range
            (:start
             (:line 11 :character 15)
             :end
             (:line 11 :character 18))
            :newText "name1")
           :sortText "0000name1"))
[server-reply] (id:55) Wed Mar 15 14:15:06 2023:
(:jsonrpc "2.0" :id 55 :result
          (:label "name1" :kind 6 :detail "=~ String" :data
                  (:path nil :return_type "undefined" :location
                         (:filename "/Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb" :range
                                    (:start
                                     (:line 9 :character 0)
                                     :end
                                     (:line 9 :character 11)))
                         :deprecated :json-false :uri "file:///Volumes/HDD/Users/gqj/Downloads/test_rb/test_dict.rb")
                  :textEdit
                  (:range
                   (:start
                    (:line 11 :character 15)
                    :end
                    (:line 11 :character 18))
                   :newText "name1")
                  :sortText "0000name1" :documentation
                  (:kind "markdown" :value "String")))