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

Saving will trigger all files to recompile and intellisense does not work during that #649

Closed
inkless opened this issue Apr 4, 2019 · 16 comments

Comments

@inkless
Copy link

inkless commented Apr 4, 2019

Result from CocInfo

## versions
vim version: NVIM v0.4.0-dev
node version: v11.8.0
coc.nvim version: 0.0.64
term: iTerm.app
platform: darwin

## Error messages

## Output channel: snippets
[Info  - 8:59:27 PM] watchman watching project: /Users/inkless/.config/coc/ultisnips
[Info  - 8:59:27 PM] subscribing "**/*.snippets" in /Users/inkless/.config/coc/ultisnips

## Output channel: watchman
[Info  - 8:59:35 PM] watchman watching project: /Users/inkless/griffin/griffin-client
[Info  - 8:59:35 PM] subscribing "**/[tj]sconfig.json" in /Users/inkless/griffin/griffin-client
[Info  - 8:59:35 PM] subscribing "**/package.json" in /Users/inkless/griffin/griffin-client
[Info  - 8:59:35 PM] subscribing "**/*.ts" in /Users/inkless/griffin/griffin-client
[Info  - 8:59:35 PM] subscribing "**/*.js" in /Users/inkless/griffin/griffin-client
[Info  - 8:59:59 PM] file change detected: {
  "unilateral": true,
  "subscription": "0fa001c0-568e-11e9-ad20-f9cba82d2161",
  "root": "/Users/inkless/griffin/griffin-client",
  "files": [
    {
      "name": "src/components/BitcoinAddressWithLink.js",
      "size": 265,
      "exists": true,
      "type": "f",
      "mtime_ms": 1554350399204,
      "ctime_ms": 1554350399204
    }
  ],
  "version": "4.9.0",
  "since": "c:1554344650:46228:4:59",
  "clock": "c:1554344650:46228:4:60",
  "is_fresh_instance": false
}

Describe the bug
When I save the a file, even without changing it, tsserver will recompile the whole project. This make all the intellisense and jump definition usable at all during recompiling.

To Reproduce

  • Create a minimal mini.vim with:
call plug#begin('~/.local/share/nvim/plugged')

Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}}
Plug 'pangloss/vim-javascript'
Plug 'HerringtonDarkholme/yats.vim'

call plug#end()

set coc-settings.json

{
  "tsserver.trace.server": "verbose",
  "tsserver.log": "verbose"
}
  • Start neovim with command: nvim -u mini.vim

  • open any js/typescript project with jsconfig.json/tsconfig.json. save one file.

  • check tsserver.log

Info 204  [21:9:53.56] DirectoryWatcher:: Triggered with /users/inkless/griffin/griffin-client/src/components/4913 :: WatchInfo: /users/inkless/griffin/griffin-client 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Wild card directory
Info 205  [21:9:53.57] Scheduled: /Users/inkless/griffin/griffin-client/jsconfig.json
Info 206  [21:9:53.57] Scheduled: *ensureProjectForOpenFiles*
Info 207  [21:9:53.57] Elapsed:: 1ms DirectoryWatcher:: Triggered with /users/inkless/griffin/griffin-client/src/components/4913 :: WatchInfo: /users/inkless/griffin/griffin-client 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Wild card directory
Info 208  [21:9:53.57] DirectoryWatcher:: Triggered with /users/inkless/griffin/griffin-client/src/components/ExternalLink.js :: WatchInfo: /users/inkless/griffin/griffin-client 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Wild card directory
Info 209  [21:9:53.57] Scheduled: /Users/inkless/griffin/griffin-client/jsconfig.json, Cancelled earlier one
Info 210  [21:9:53.58] Scheduled: *ensureProjectForOpenFiles*, Cancelled earlier one
Info 211  [21:9:53.58] Elapsed:: 1ms DirectoryWatcher:: Triggered with /users/inkless/griffin/griffin-client/src/components/ExternalLink.js :: WatchInfo: /users/inkless/griffin/griffin-client 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Wild card directory
Info 212  [21:9:53.58] DirectoryWatcher:: Triggered with /users/inkless/griffin/griffin-client/src/components/ExternalLink.js~ :: WatchInfo: /users/inkless/griffin/griffin-client 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Wild card directory
Info 213  [21:9:53.58] Project: /Users/inkless/griffin/griffin-client/jsconfig.json Detected file add/remove of non supported extension: /users/inkless/griffin/griffin-client/src/components/ExternalLink.js~
Info 214  [21:9:53.58] Elapsed:: 0ms DirectoryWatcher:: Triggered with /users/inkless/griffin/griffin-client/src/components/ExternalLink.js~ :: WatchInfo: /users/inkless/griffin/griffin-client 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Wild card directory
Info 215  [21:9:53.58] DirectoryWatcher:: Triggered with /Users/inkless/griffin/griffin-client/src/components/4913 :: WatchInfo: /Users/inkless/griffin/griffin-client/src 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Failed Lookup Locations
Info 216  [21:9:53.58] Elapsed:: 0ms DirectoryWatcher:: Triggered with /Users/inkless/griffin/griffin-client/src/components/4913 :: WatchInfo: /Users/inkless/griffin/griffin-client/src 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Failed Lookup Locations
Info 217  [21:9:53.58] DirectoryWatcher:: Triggered with /Users/inkless/griffin/griffin-client/src/components/ExternalLink.js :: WatchInfo: /Users/inkless/griffin/griffin-client/src 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Failed Lookup Locations
Info 218  [21:9:53.59] Scheduled: /Users/inkless/griffin/griffin-client/jsconfig.json, Cancelled earlier one
Info 219  [21:9:53.59] Scheduled: *ensureProjectForOpenFiles*, Cancelled earlier one
Info 220  [21:9:53.59] Elapsed:: 1ms DirectoryWatcher:: Triggered with /Users/inkless/griffin/griffin-client/src/components/ExternalLink.js :: WatchInfo: /Users/inkless/griffin/griffin-client/src 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Failed Lookup Locations
Info 221  [21:9:53.59] DirectoryWatcher:: Triggered with /Users/inkless/griffin/griffin-client/src/components/ExternalLink.js~ :: WatchInfo: /Users/inkless/griffin/griffin-client/src 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Failed Lookup Locations
Info 222  [21:9:53.59] Elapsed:: 0ms DirectoryWatcher:: Triggered with /Users/inkless/griffin/griffin-client/src/components/ExternalLink.js~ :: WatchInfo: /Users/inkless/griffin/griffin-client/src 1 Project: /Users/inkless/griffin/griffin-client/jsconfig.json WatchType: Failed Lookup Locations
Info 223  [21:9:53.309] Running: /Users/inkless/griffin/griffin-client/jsconfig.json
Info 224  [21:9:53.317] Starting updateGraphWorker: Project: /Users/inkless/griffin/griffin-client/jsconfig.json
Info 225  [21:9:56.252] Finishing updateGraphWorker: Project: /Users/inkless/griffin/griffin-client/jsconfig.json Version: 5 structureChanged: true Elapsed: 2935ms
Info 226  [21:9:56.255] Running: *ensureProjectForOpenFiles*
Info 227  [21:9:56.255] Structure before ensureProjectForOpenFiles:
Info 228  [21:9:56.255] Project '/Users/inkless/griffin/griffin-client/jsconfig.json' (Configured) 0
Info 228  [21:9:56.255]         Files (1328)
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es5.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2015.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2016.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2017.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2018.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.dom.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.webworker.importscripts.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.scripthost.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2015.core.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2015.collection.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2015.generator.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2015.iterable.d.ts

@inkless inkless changed the title Saving will trigger all files to recompile Saving will trigger all files to recompile and intellisense does not work during that Apr 4, 2019
@chemzqm
Copy link
Member

chemzqm commented Apr 4, 2019

It's feature of tsserer, the problem is

Info 225  [21:9:56.252] Finishing updateGraphWorker: Project: /Users/inkless/griffin/griffin-client/jsconfig.json Version: 5 structureChanged: true Elapsed: 2935ms

Notice structureChanged: true makes it slow, but it should not happen unless you have jsconfig.json or tsconfig.json changed.

@inkless
Copy link
Author

inkless commented Apr 4, 2019

@chemzqm I tried multiple projects, looks like the structureChanged returns true for some project but not all projects. Can you check out this project: https://github.com/react-boilerplate/react-boilerplate/
I cannot share my project, but I can reproduce this in the react-boilerplate project.
And I added this jsconfig.json in the root:

{
  "compilerOptions": {
    "module": "es2015",
    "baseUrl": "app"
  },
  "exclude": ["node_modules"]
}

@chemzqm
Copy link
Member

chemzqm commented Apr 4, 2019

Because your configuration is wrong, you should use paths instead of baseUrl.

@chemzqm chemzqm closed this as completed Apr 4, 2019
@inkless
Copy link
Author

inkless commented Apr 4, 2019

@chemzqm I don't think that matters, I just created a random jsconfig.json
it's the same even if the jsconfig.json is:

{
  "compilerOptions": {
    "module": "es2015"
  }
}

@chemzqm
Copy link
Member

chemzqm commented Apr 4, 2019

Same problem with VSCode, ask https://github.com/Microsoft/TypeScript for help.

@inkless
Copy link
Author

inkless commented Apr 4, 2019

I actually checked VS Code 's tsserver.log, it does not have this issue.
When I save, it doesn't really do the same thing.
The intellisense works smoothly as well.

@inkless
Copy link
Author

inkless commented Apr 4, 2019

@chemzqm Actually I noticed a very interesting thing, not sure if it can remind you anything:
If I open a file in vim, then go to terminal do:

echo '; const a = 1;' >> /path/to/that_file.js

then come back to vim and

:e!

The structureChanged is false.

But if I just do :w in the same file, it's true

I only have one file in buffers, and I didn't use :wa, so the jsconfig.json shouldn't be updated by my :w.

@chemzqm
Copy link
Member

chemzqm commented Apr 4, 2019

I got same behavior with VSCode.
The jsconfig.json file is not changed at least for me.
You can get all the message coc.nvim send to tsserver by using output channel of tsserver.

@chemzqm
Copy link
Member

chemzqm commented Apr 4, 2019

Although I have log same as your's but I didn't experience any slow for completion or goto definition request just after save.
So I think you should try to reproduce the problem with minimal vimrc.

@inkless
Copy link
Author

inkless commented Apr 4, 2019

Here's my complete vimrc:

inoremap jk <ESC>
call plug#begin('~/.local/share/nvim/plugged')

Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}}
Plug 'pangloss/vim-javascript'
Plug 'HerringtonDarkholme/yats.vim'

call plug#end()

nmap <silent> <c-]> <Plug>(coc-definition)

nvim-ts-log after :w without code change

Info 1403 [9:57:0.829] DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/4913 :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Wild card directory
Info 1404 [9:57:0.830] Scheduled: /Users/inkless/ali/client/core/jsconfig.json
Info 1405 [9:57:0.830] Scheduled: *ensureProjectForOpenFiles*
Info 1406 [9:57:0.830] Elapsed:: 1ms DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/4913 :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Wild card directory
Info 1407 [9:57:0.830] DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/service.js :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Wild card directory
Info 1408 [9:57:0.830] Scheduled: /Users/inkless/ali/client/core/jsconfig.json, Cancelled earlier one
Info 1409 [9:57:0.830] Scheduled: *ensureProjectForOpenFiles*, Cancelled earlier one
Info 1410 [9:57:0.830] Elapsed:: 0ms DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/service.js :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Wild card directory
Info 1411 [9:57:0.830] DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/service.js~ :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Wild card directory
Info 1412 [9:57:0.831] Project: /Users/inkless/ali/client/core/jsconfig.json Detected file add/remove of non supported extension: /Users/inkless/ali/client/core/addon/embedded-app/service.js~
Info 1413 [9:57:0.831] Elapsed:: 1ms DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/service.js~ :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Wild card directory
Info 1414 [9:57:0.831] DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/4913 :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Failed Lookup Locations
Info 1415 [9:57:0.831] Elapsed:: 0ms DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/4913 :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Failed Lookup Locations
Info 1416 [9:57:0.831] DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/service.js :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Failed Lookup Locations
Info 1417 [9:57:0.831] Scheduled: /Users/inkless/ali/client/core/jsconfig.json, Cancelled earlier one
Info 1418 [9:57:0.831] Scheduled: *ensureProjectForOpenFiles*, Cancelled earlier one
Info 1419 [9:57:0.831] Elapsed:: 0ms DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/service.js :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Failed Lookup Locations
Info 1420 [9:57:0.831] DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/service.js~ :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Failed Lookup Locations
Info 1421 [9:57:0.832] Elapsed:: 1ms DirectoryWatcher:: Triggered with /Users/inkless/ali/client/core/addon/embedded-app/service.js~ :: WatchInfo: /Users/inkless/ali/client/core/addon 1 Project: /Users/inkless/ali/client/core/jsconfig.json WatchType: Failed Lookup Locations
Info 1422 [9:57:1.81] Running: /Users/inkless/ali/client/core/jsconfig.json
Info 1423 [9:57:1.142] Starting updateGraphWorker: Project: /Users/inkless/ali/client/core/jsconfig.json
Info 1424 [9:57:8.41] Finishing updateGraphWorker: Project: /Users/inkless/ali/client/core/jsconfig.json Version: 29 structureChanged: true Elapsed: 6899ms
Info 1425 [9:57:8.43] Running: *ensureProjectForOpenFiles*
Info 1426 [9:57:8.43] Structure before ensureProjectForOpenFiles:
Info 1427 [9:57:8.43] Project '/Users/inkless/ali/client/core/jsconfig.json' (Configured) 0
Info 1427 [9:57:8.43]   Files (1006)
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es5.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2015.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2016.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2017.d.ts
        /Users/inkless/.config/coc/extensions/node_modules/typescript/lib/lib.es2018.d.ts

Notice the structureChanged: true Elapsed: 6899ms, during this 7 seconds, my intellisense stop working.

coc tsserver channel

[Trace  - 9:57:08 AM] Event received: projectsUpdatedInBackground (0).
Data: {
    "openFiles": [
        "/Users/inkless/ali/client/core/addon/embedded-app/service.js"
    ]
}

Can you point me where I should look at in coc.vim's code to help identify the issue? I'm wondering where do we send message to tsserver.js to notify the file is saved.

@inkless
Copy link
Author

inkless commented Apr 4, 2019

hmm, I think I might know what's going on.... It might be related to vim's weird 4913 file in nocompatible or the filename~ in compatible mode..
Let me test that.

@inkless
Copy link
Author

inkless commented Apr 4, 2019

I think that's why... VIM just always create a file to check if the directory is writable..
Discussion here
https://groups.google.com/forum/#!topic/vim_dev/sppdpElxY44
And code here:
https://github.com/vim/vim/blob/2c519cf3bfe76083767ac94c674d2e161ed36587/src/fileio.c#L3647

And every time when a new file is created, it makes the tsserver to think the structure is changed..
I think the root cause was found, got any idea how to workaround this? @chemzqm

@inkless
Copy link
Author

inkless commented Apr 4, 2019

And I do agree this has nothing to do with coc.nvim now. I can reproduce this easily by doing something like
cp src/App.js src/4913 && mv src/4913 src/App.js in vscode, it will have exactly the same issue.
I've tried to add "include": ["**/*.js"] in jsconfig.json but it doesn't seem to take effect.
Currently I think it's likely just typescript's problem. I'll probably fire an issue there. But before I continue, just curious do you know configuration for tsserver might be able to provide some workaround?

@inkless
Copy link
Author

inkless commented Apr 4, 2019

I tried several methods and dived into typescript source code, the mv src/4913 src/App.js is treated very different from a normal save.
And it doesn't seem there's workaround from typescript. I guess the only direction I can think of is from the vim side. But it seems pretty hard as well...
I've tried

set nobackup
set backupcopy=no
set noswapfile
set noundofile

Nothing really work...
I'll probably switch back to nvim-typescript for now, hopefully this can be addressed some day.
Thanks for this awesome plugin anyway! @chemzqm

@inkless
Copy link
Author

inkless commented Apr 4, 2019

Ah I finally got it work, there's another set nowritebackup
So all I need is:

setlocal nobackup
setlocal nowritebackup

Finally! 💯

@chemzqm
Copy link
Member

chemzqm commented Apr 5, 2019

Looks like related to microsoft/TypeScript#30663, I've downgrade tsserver to 3.3.4000 to avoid this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants