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

tsconfig --resolveJsonModules ignored in dot directories #366

Closed whitestripe42 closed 2 years ago

whitestripe42 commented 2 years ago

Describe the bug

Importing JSON from a directory outside of a dotted directory gives an error, even though compilerOptions.resolveJsonModules is true in my tsconfig.json.

Reproduce the bug

$ mkdir project
$ cd project
$ mkdir .something config
$ echo "{ \"someValue\": 1 }" > config/config.json
$ echo "import { someValue } from \"../config/config.json\"" > .something/index.ts
$ echo "{ \"compilerOptions\": { \"resolveJsonModule\": true } }" > tsconfig.json
$ cp .something something

$ tree
.
├── config
│   └── config.json
├── something
│   └── index.ts
└── tsconfig.json

There is no error in something/index.ts, however, in .something/index.ts I get an error:

Cannot find module '../config/config.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
[tsserver: 2732]

init.vim

set runtimepath^=~/.local/share/nvim/
set nocompatible
filetype plugin indent on
syntax on
set hidden

call plug#begin(stdpath('data') . '/plugged')
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
call plug#end()

coc-extensions

coc-eslint
coc-git
coc-json
coc-prettier
coc-tsserver
coc-clangd
coc-cmake
coc-cssmodules

Result from CocInfo

vim version: NVIM v0.7.0
node version: v17.4.0
coc.nvim version: 0.0.80-1f60c3d886
coc.nvim directory: /home/x/.local/share/nvim/plugged/coc.nvim
term: st-256color
platform: linux

Log of coc.nvim

2022-04-28T11:54:02.436 INFO (pid:5478) [coc-git] - Looking for git in: git
2022-04-28T11:54:02.889 INFO (pid:5478) [plugin] - coc.nvim initialized with node: v17.4.0 after 597ms
2022-04-28T11:54:05.899 INFO (pid:5478) [services] - registered service "eslint"
2022-04-28T11:54:05.900 INFO (pid:5478) [services] - ESLint state change: stopped => starting
2022-04-28T11:54:05.932 INFO (pid:5478) [services] - registered service "tsserver"
2022-04-28T11:54:05.964 INFO (pid:5478) [services] - service tsserver started
2022-04-28T11:54:06.039 INFO (pid:5478) [services] - ESLint state change: starting => running
2022-04-28T11:54:06.044 INFO (pid:5478) [services] - service eslint started
2022-04-28T11:56:45.843 WARN (pid:5478) [extension:coc-prettier] - jsxBracketSameLine is deprecated.
2022-04-28T11:56:45.868 INFO (pid:5478) [attach] - Request action: doAutocmd [ 1, 3 ]
2022-04-28T11:57:52.920 INFO (pid:5478) [attach] - receive notification: showInfo []
whitestripe42 commented 2 years ago

Seems like this can be fixed by explicitly adding the dotted directory to tsconfig.json's include array, however, it isn't picked up if include just contains a wild card like ./**/*. Further, other tools consuming the same tsconfig.json seem to pick the directory up with just the wildcard.

// tsconfig.json

// Works
include: [".something/**/*"]

// Import error in tsserver, but not in other tools
include: ["./**/*"]
whitestripe42 commented 2 years ago

https://github.com/microsoft/TypeScript/issues/13399

Okay, seems like this behaviour is correct, and the "other tools" (in this case, Webpack with Typescript config file) are probably transpiling their config files irrespective of the directory structure.