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

files.associations "javascript" not forwarded to TypeScript Service #15460

Closed
andiby opened this issue Nov 14, 2016 · 7 comments
Closed

files.associations "javascript" not forwarded to TypeScript Service #15460

andiby opened this issue Nov 14, 2016 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality javascript JavaScript support issues typescript Typescript support issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@andiby
Copy link

andiby commented Nov 14, 2016

  • VSCode Version: 1.7.1
  • OS Version: Windows 10

Steps to Reproduce:

  1. Create a JS file with a file extension other than .js
    e.q. "javascript.es6" with content "var fs = require('fs');"
  2. Associate this file extension with "javascript"
    Use UI "Select Language Mode" for that or set "files.associations": {"*.es6":"javascript"}
  3. Got Error "Cannot find name 'require'"

This is because TypeScript Service associate this file as TypeScript (getScriptKindFromFileName default) if it does not get the scriptKindName from VS Code.
And VS Code only sets the scriptKindName for files without file extensions:
extensions/typescript/src/features/bufferSyncSupport.ts

// we have no extension. So check the mode and
// set the script kind accordningly.
const ext = path.extname(this.filepath);
if (ext === '') {
	const scriptKind = Mode2ScriptKind[this.document.languageId];
	if (scriptKind) {
		args.scriptKindName = scriptKind;
	}
}

I think TypeScript Service should always use the scriptKind selected in VS Code, especially for file extionsions not known by the TypeScript Service.

@andiby
Copy link
Author

andiby commented Nov 14, 2016

Would also solve #13100 and #9591

@mjbvz mjbvz added the javascript JavaScript support issues label Nov 14, 2016
@ramya-rao-a ramya-rao-a added the typescript Typescript support issues label Nov 15, 2016
@waderyan waderyan added the feature-request Request for new features or functionality label Dec 9, 2016
@waderyan
Copy link

waderyan commented Dec 9, 2016

@mjbvz what are your thoughts on this? Seems reasonable..

@dbaeumer would be good to get your perspective as this is code I believe you wrote.

@waderyan
Copy link

waderyan commented Dec 9, 2016

Oh, sorry @dbaeumer I was thinking this code was closer to the TS Service code you have written.

@dbaeumer
Copy link
Member

@waderyan I wrote that code and the reason for this is as follows: the script kind can only be set for a single open file. We can't tell the tsserver to treat all file with es6 extension as JS. As a result something like this will not work

  • a.es6
  • b.es6 importing a.es6
  • user opens b.es6

We would treat it as JS and you would get code assist for stuff, ... however the import to a would be errored and you would not get any code complete for anything from a.es6. The reason is that the tsserver would only look for a a.js, a.ts or a.d.ts file and NOT for a.es6.

Since this would even be more confusing I don't sent the scriptKind for all file. The reason why I do it for file without extension is the #! node ... case which usually requires other JS files with js extension.

@andiby
Copy link
Author

andiby commented Dec 13, 2016

@dbaeumer The main focus here is viewing and editing files in VS Code.
Currently I get lots of "Cannot find name 'require'" errors.
And lots of other "Cannot find name '...'" errors for my globals defined in ".eslintrc"

I fix the bufferSyncSupport.ts for me so that it always sends the scriptType and all these errors disappear.
And I don't get any error for requiring other *.es6 files, they just return type any.

So the question is: Do I want confusion errors or just be able to use the editor?
I want to use the editor without wrong red errors.

The code completion does not work in both cases, so it's an other problem that should be solved.

@dbaeumer
Copy link
Member

Agree that the require will not give a red underline for the JS case. However there will still be no smartness here.

So what we could do is to send the script kind for JS, but we should definitely not do it for TS since it will make things definitely worse.

@mjbvz can you look into this. Change should be easy.

@mjbvz
Copy link
Collaborator

mjbvz commented Feb 15, 2017

I believe this was handled by #20351

@mjbvz mjbvz closed this as completed Feb 15, 2017
@mjbvz mjbvz added this to the February 2017 milestone Feb 15, 2017
@mjbvz mjbvz added the verification-needed Verification of issue is requested label Feb 22, 2017
@jrieken jrieken added the verified Verification succeeded label Feb 22, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality javascript JavaScript support issues typescript Typescript support issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants