sublimelsp / LSP-typescript

TypeScript, JavaScript support for Sublime LSP plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NPM jQuery and @types/jquery global support

todordvv opened this issue · comments

jQuery autocomplete doesn't work when jQuery and @types/jquery are installed globally. When they are defined within a project they work.

When including

require('jQuery');

at the start of a file it works. I think there needs to be a way for typescript to read the global configuration and detect that jQuery and @types/jquery are globally setup/required and for autocomplete to work on any opened javascript file.

Or alternatively maybe a way to set it up in initializationOptions or any other way to just set this up if preferred?

Thanks in advance.


Additional info and things tried:

#199

sublimelsp/LSP-html#40

Hello 👋

There is nothing that LSP-typescript can do about it.

This has to be supported by typescript itself.
There was this issue at the typescript repo that requested the same thing that you are asking for,
but typescript intentionally does not support that use case.
microsoft/TypeScript#30523 (comment)

so I will close this issue.

Hello 👋

There is nothing that LSP-typescript can do about it.

This has to be supported by typescript itself. There was this issue at the typescript repo that requested the same thing that you are asking for, but typescript intentionally does not support that use case. microsoft/TypeScript#30523 (comment)

so I will close this issue.

Thank you so much for sharing this, definitely brings much to light.

Out of curiosity, any chance that the client plugin can somehow prepend code to the JS file before sending to the server (once again I'm a noob so hopefully I'm not talking nonsense about code being sent to typescript server)?
Cause if there is a way to do that I'd just prepend the line "require('jQuery');" before the code is sent.

I'm just desperately trying to see if I can avoid writing that line in a file before working on it, and then removing it before saving the file on server hahahah. I don't mind if I have to edit plugin code for a custom solution just for myself if this is doable, but if this kinda workaround is possible it would be nice if there was an option for it down the line.

Again sorry if I'm asking or proposing stupid things and THANK YOU so much for the explanation and also in advance if you could further indulge me!

Yes you can avoid the need to add require('jQuery') to make typescript language server aware that jquery exist in the project.

You need need @types/jquery and jquery installed in the local project, and that is it.
This video show that it works even without the require('jQuery').
Screencast from 2023-02-25 20-18-26.webm

Unzip the file, and run npm i at the root of the unzipped folder
and the example will work
jqu.zip

Yes you can avoid the need to add require('jQuery') to make typescript language server aware that jquery exist in the project.

You need need @types/jquery and jquery installed in the local project, and that is it. This video show that it works even without the require('jQuery'). Screencast from 2023-02-25 20-18-26.webm

Unzip the file, and run npm i at the root of the unzipped folder and the example will work jqu.zip

Once again thanks so much for the reply. I am aware I can do this in projects the problem is I'm trying to have autocomplete in files edited via FTP (which are not saved inside a project folder).

Triple slash syntax with having types installed in a fixed path is also an option, like so:

/// <reference path="C:\dev-tools\node_modules\@types\jquery\index.d.ts" />

which again isn't too much to do, I can make a key binding to insert this line with a key combination, and am researching if there is a way to add references to JS files via some option (without having the code in the file) or some other workaround.

I learned a lot in any case, and it's all thanks to your comments and guidance!! So once again thank you @predragnikolic - I hope I may find a way to include these references and make all this seamless.

I would personally just create a local project that includes @types/jquery and sync it with the FTP server using some external software or a package like SFTP (paid).

Making jquery types available globally for all projects strikes me as wrong and typescript is not really designed to work this way. You define dependencies for the project you are working on.

I would personally just create a local project that includes @types/jquery and sync it with the FTP server using some external software or a package like SFTP (paid).

Making jquery types available globally for all projects strikes me as wrong and typescript is not really designed to work this way. You define dependencies for the project you are working on.

In my case, we use jQuery for probably all projects we work on. Subjective opinions aside whether that's good, bad or what-not it doesn't change the fact that in my not-so-common scenario I want to find a way to include it globally.

Ideally by adding an additional path to be scanned for JS files that are opened. I am looking into options to make this happen via some other plugin or writing a new plugin for this specific purpose.

Heck I'd even be satisfied with the jquery types being loaded for every file I work on (setting up global working directory to some custom path where I have a project config file that includes these types). It's not even a 1% performance hit for my machine.

When you are opening those files locally, where are those located? Is it always the same directory or it's a Temp directory? As long as you have @types/jquery installed somewhere higher in the directory tree then I think typescript will pick it up.

Or you could adjust your flow so that those are always downloaded to specific directory that has jquery types installed...

When you are opening those files locally, where are those located? Is it always the same directory or it's a Temp directory? As long as you have @types/jquery installed somewhere higher in the directory tree then I think typescript will pick it up.

Or you could adjust your flow so that those are always downloaded to specific directory that has jquery types installed...

Hmm, I can try adding it in a folder that's above in the hierarchy. I believe they are opened in a WINSCP portable installation, so if I add these to WINSCP main DIR it should work? Let me give that a shot.

THAT WORKED!!! Thank you @rchl so so so much!!!!!