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

fix: completion for strings with trigger character #492

Conversation

DeMoorJasper
Copy link
Contributor

Pull Request

When trying to type a string with a trigger character the autocompletion does not return a testEdit, causing editors to append the text resulting in duplication and unwanted behaviour.

Explanation

Had a completion result with the following content:

{
   "name": "hello/world",
   "kind": "string",
   "kindModifiers": "",
   "sortText": "11",
   "replacementSpan": {
      "start": {
         "line": 9,
         "offset": 11
      },
      "end": {
         "line": 9,
         "offset": 12
      }
   }
}

Got transformed into:

{
   "label":"hello/world",
   "kind":21,
   "sortText":"11",
   "data":{
      "file":"/Users/jasper/projects/codesandbox/pitcher/packages/pitcher-agent/workspace/codesandbox/test-sandbox/draft/priceless-curran/pages/_app.tsx",
      "line":9,
      "offset":12,
      "entryNames":[
         "hello/world"
      ]
   }
}

But the correct one is:

{
   "label":"hello/world",
   "kind":21,
   "sortText":"11",
   "data":{
      "file":"/Users/jasper/projects/codesandbox/pitcher/packages/pitcher-agent/workspace/codesandbox/test-sandbox/draft/priceless-curran/pages/_app.tsx",
      "line":9,
      "offset":12,
      "entryNames":[
         "hello/world"
      ]
   },
   "textEdit":{
      "range":{
         "start":{
            "line":8,
            "character":10
         },
         "end":{
            "line":8,
            "character":11
         }
      },
      "newText":"hello/world"
   }
}

Code to reproduce this:

function test(value: "fs/read" | "hello/world") {
  return true;
}

test("fs/")

When the cursor is after test("fs/ and tries to autocomplete it fails causing test("fs/fs/read") instead of test("fs/read")

@@ -588,7 +588,9 @@ export class LspServer {
const result = await this.interuptDiagnostics(() => this.tspClient.request(CommandTypes.CompletionInfo, {
file,
line: params.position.line + 1,
offset: params.position.character + 1
offset: params.position.character + 1,
triggerCharacter: getCompletionTriggerCharacter(params.context?.triggerCharacter),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part doesn't really seem relevant to fixing the issue but it's good to have nonetheless.

@rchl rchl merged commit 76bf9a4 into typescript-language-server:master Jun 13, 2022
@rchl rchl changed the title fix: Completion for strings with trigger character fix: completion for strings with trigger character Jun 13, 2022
@rchl
Copy link
Member

rchl commented Jun 13, 2022

Thanks!

@DeMoorJasper DeMoorJasper deleted the fix/completion-trigger-kind branch June 13, 2022 13:53
rchl added a commit that referenced this pull request Jul 23, 2022
* master:
  chore(deps): add renovate configuration
  chore(lint): enable "no-constant-binary-expression" rule
  chore(deps): bump commander from 9.3.0 to 9.4.0 (#527)
  chore(deps-dev): bump @typescript-eslint/eslint-plugin from 5.28.0 to 5.30.7 (#521)
  chore(deps-dev): bump @typescript-eslint/parser from 5.30.6 to 5.30.7 (#526)
  chore(deps-dev): bump concurrently from 7.2.2 to 7.3.0 (#523)
  chore(deps-dev): bump eslint from 8.18.0 to 8.20.0 (#522)
  chore(deps-dev): bump @typescript-eslint/parser from 5.27.1 to 5.30.6 (#515)
  chore(deps-dev): bump ts-node from 10.8.1 to 10.9.1 (#518)
  chore(master): release 0.11.2 (#503)
  chore(deps-dev): bump eslint from 8.17.0 to 8.18.0 (#498)
  chore(deps-dev): bump @typescript-eslint/eslint-plugin from 5.27.1 to 5.28.0 (#499)
  chore(deps-dev): bump concurrently from 7.2.1 to 7.2.2 (#500)
  fix: apply refactoring returns -1 positions in ranges (#502)
  chore(master): release 0.11.1 (#494)
  fix: completion for strings with trigger character (#492)
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

Successfully merging this pull request may close these issues.

None yet

2 participants