sourcegraph / javascript-typescript-langserver

JavaScript and TypeScript code intelligence through the Language Server Protocol
https://sourcegraph.com
Apache License 2.0
793 stars 72 forks source link

How to set up a pure JS project #533

Open ckuchimanchi opened 5 years ago

ckuchimanchi commented 5 years ago

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!

felixfbecker commented 5 years ago

The language server already reads jsconfig.json

ckuchimanchi commented 5 years ago

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 commented 5 years ago

Hi - Can anyone please help me with this?

ggilmore commented 5 years ago

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

felixfbecker commented 5 years ago

I don't know what could be the cause here

jmartin84 commented 5 years ago

I've been seeing a similar issue in emacs

orzechowskid commented 5 years ago

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.

cjk commented 5 years ago

@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/**/*"]
}
ragnese commented 5 years ago

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.

karolyi commented 5 years ago

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.