Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Insert completion snippet when in front of local var (#7877)
* Fix error message in position_assertions.cc * Add a failing test case + exec test/lsp_test_runner --single_test=test/testdata/lsp/completion/snippet_before_variable.rb Pausing Resuming [doctest] doctest version is "2.4.9" [doctest] run with "--help" for options =============================================================================== test/lsp_test_runner.cc:525: TEST CASE: LSPTest test/helpers/expectations.cc:209: ERROR: The expected (rbedited) file contents for this completion did not match the actual file contents post-edit @@ -9,7 +9,7 @@ end begin - A.example(${1:Integer})${0} + A.example${0} # ^ completion: example, ... # ^ apply-completion: [B] item: 0 =============================================================================== [doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped [doctest] assertions: 67 | 66 passed | 1 failed | [doctest] Status: FAILURE! ================================================================================ * Fix failing test What's happening here is that Sorbet sees foo0 = Foo. foo1 = Foo.new(1, 2) as the same as this: foo0 = Foo.foo1=(Foo.new(1, 2)) They both have this parse result: ❯ sorbet -p desugar-tree -e $'foo0 = Foo.\n foo1 = Foo.new(1, 2)\n' 2> /dev/null class <emptyTree><<C <root>>> < (::<todo sym>) foo0 = <emptyTree>::<C Foo>.foo1=(<emptyTree>::<C Foo>.new(1, 2)) end Which makes it hard for sorbet to distinguish this from a differen case, where it likely wouldn't make sense to insert a snippet: x = self.already_has_args(1, 2) # ^ completion: ... This change attempts to disambiguate that by checking whether the query location is at the end of the line. This is simplistic (even a whitespace character at the end of the line will break this heuristic), but I think that eventually we should probably stop attempting to generate snippets for method completion items because other language clients don't do it, and there's a better LSP method to guide people towards filling in arguments, namely signature helper.
- Loading branch information