neoclide / coc-tsserver

Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
MIT License
1.05k stars 68 forks source link

Incorrect behavior on completion import #381

Closed ghost closed 2 years ago

ghost commented 2 years ago

Problem

If lines are together and trying to import - such bug appears. Before: Screenshot_2022-06-14_15-56-22 After: Screenshot_2022-06-14_15-56-42

versions

vim version: NVIM v0.8.0-dev+404-g2b539d6fd node version: v16.15.1 coc.nvim version: 0.0.81-2522eee 2022-06-14 19:03:29 +0800 coc.nvim directory: /home/user/.local/share/nvim/plugged/coc.nvim term: xterm-256color platform: linux

Log of coc.nvim

2022-06-14T15:57:48.661 INFO (pid:51042) [services] - registered service "languageserver.tailwind-lsp" 2022-06-14T15:57:49.004 INFO (pid:51042) [plugin] - coc.nvim initialized with node: v16.15.1 after 475ms 2022-06-14T15:57:49.772 INFO (pid:51042) [attach] - receive notification: openList [ 'files' ] 2022-06-14T15:57:51.474 INFO (pid:51042) [services] - tailwind-lsp state change: stopped => starting 2022-06-14T15:57:51.547 INFO (pid:51042) [services] - registered service "tsserver" 2022-06-14T15:57:51.611 INFO (pid:51042) [services] - service tsserver started 2022-06-14T15:57:51.634 INFO (pid:51042) [language-client-index] - Language server "languageserver.tailwind-lsp" started with 51080 2022-06-14T15:57:52.012 INFO (pid:51042) [services] - tailwind-lsp state change: starting => running 2022-06-14T15:57:52.018 INFO (pid:51042) [services] - service languageserver.tailwind-lsp started 2022-06-14T15:57:53.042 INFO (pid:51042) [core-watchman] - watchman watching project: /home/user/TS/app 2022-06-14T15:58:06.518 INFO (pid:51042) [snippets-session] - Content change before snippet, reset snippet position 2022-06-14T15:58:06.524 INFO (pid:51042) [snippets-session] - Content change before snippet, reset snippet position 2022-06-14T15:58:06.538 INFO (pid:51042) [attach] - receive notification: showSignatureHelp [] 2022-06-14T15:58:09.675 INFO (pid:51042) [attach] - receive notification: showInfo []

chemzqm commented 2 years ago

Try minimal vimrc.

jeffshaver commented 2 years ago

This is also happening to me. Specifically though, its in a file that has no imports yet. so when if my entire file contents are

function useHook () {
  const a = useState()
}

and then i get auto completion from coc for useState and hit enter, than my file gets changed to

import {useState} from "react";

  const a = useState(initialState)()
  const a = useState(initialState)()
}

however, if i have an import at the top, and this is my file content

import {useEffect} from 'react'                                                 

function useHook () {                                                                                                                    
  const a = useState()                                                          
}

than when i auto complete for useState, i get

import {useEffect, useState} from 'react'                                                 

function useHook () {                                                                                                                    
  const a = useState(initialState)()
}

the latter is more correct (minus the double call to useState), but it doesn't mess up the imports.

so for me it happens consistently when i have no imports and then try to import via auto completion.

chemzqm commented 1 year ago

Fixed on latest release branch of coc.nvim.