javascript-typescript-langserver icon indicating copy to clipboard operation
javascript-typescript-langserver copied to clipboard

How to set up a pure JS project

Open ckuchimanchi opened this issue 7 years ago • 10 comments

Hi,

The LSP works fine on a single JS file -- it identifies "go to definition" etc.

But what if I have a bunch of js files in a folder and want to work on a type that's defined in another file. Go to definition doesn't work there. I think for it to happen, LSP should support a "project definition" file like tsconfig.json (for typescript) in javascript projects as well --

A quick search reveals, visual studio code does support such a file - jsconfig.json

Not sure if such a thing is supported by LSP? If so, does this implementation adhere to it? I tried creating that file but looks like it's not working.

Can you please advise?

Thanks!

ckuchimanchi avatar Oct 04 '18 11:10 ckuchimanchi

The language server already reads jsconfig.json

felixfbecker avatar Oct 04 '18 11:10 felixfbecker

Thanks for the quick response @felixfbecker. Can you please tell me if the below jsconfig.json is appropriate?

{ "include": [ "snc/**/*.js" ] } I'm trying to include all .js files under 'snc' folder in all subdirectories.

It doesn't seem to be working.

Go to definition isn't working f the class/type is present in another file. However, If I open the file manually and then go back and do go to definition, it works!

Any help would be appreciated. Thank you.

ckuchimanchi avatar Oct 05 '18 06:10 ckuchimanchi

Hi - Can anyone please help me with this?

ckuchimanchi avatar Oct 11 '18 11:10 ckuchimanchi

I'll defer to @felixfbecker, but are you sure that you didn't mean src instead of snc?

ggilmore avatar Oct 11 '18 18:10 ggilmore

I don't know what could be the cause here

felixfbecker avatar Oct 11 '18 18:10 felixfbecker

I've been seeing a similar issue in emacs

jmartin84 avatar Oct 17 '18 18:10 jmartin84

yep, I'm seeing this with emacs as well (specifically, eglot-mode plus flymake-mode). Setting my tsconfig.json to

{
    "compilerOptions": {
        "allowJs": true
    },
    "exclude": [
        "node_modules"
    ],
    "include": [
        "src/**/*"
    ]
}

did not help; flymake still displays TypeScript error messages.

orzechowskid avatar Dec 13 '18 04:12 orzechowskid

@orzechowskid What kind of error-messages are you seeing?

The following jsconfig.json file is working for me (my js-files reside under ./src):

{
  "compilerOptions": {
    "target": "es2017",
    "module": "es2015",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "noEmit": true,
    "checkJs": true,
    "allowJs": true,
    "lib": ["es2017"],
    "baseUrl": "./src"
  },
  "exclude": ["node_modules"],
  "include": ["src/**/*"]
}

cjk avatar Jan 08 '19 10:01 cjk

I'm having the same issue where the LS is not able to see modules imported from other files. The error message is clearly running Typescript code checking even though the files are JavaScript and I have a jsconfig.json written exactly as @ckj's example. I've tried many config options. I'm also using Emacs with lsp-mode.

ragnese avatar Jan 08 '19 14:01 ragnese

I have a JS project developed for the frontend part of my application with webpack, and this project doesn't give any code completions to it. I'm investigating the issue for more than an hour now, it's getting frustrating.

jsconfig.json doesn't seem to help.

karolyi avatar Jun 29 '19 13:06 karolyi