-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Send Script Kind based on languageId for js and ts files #20351
Send Script Kind based on languageId for js and ts files #20351
Conversation
@mjbvz SO would prefer I not "thank you" in the comments over there, so I'll thank you here :). I really appreciate you looking at this and knocking it out so quickly. |
Thanks. Looking into this issue also revealed a few other inconsistent behaviors around custom file extensions that I'm going to investigate. Please let me know if you run into any other problems with this scenario and I'll take a look. |
@mjbvz there is a deeper underlying reason why we only do this for files without extension (typically script files). The tsserver can not resolve filenames other than with ts or js extension. If users for example have a file a.custom which has an import onto b and the filename of b is b.custom the TS server will issue an error on the import since it tries to find b.ts or b.d.ts or b.js (at least when I last tested it). This will IMO be very confusing. So before releasing this please check if the tsserver has fixed this. Otherwise you will get a new set of issues you can't fix :-) |
@dbaeumer @mjbvz Even if that's still the case, I think this change will work for my scenario. As I imagine is typical, we have a gulp-based process that transpiles But as I think on it further, if the tsserver only resolves file names with a |
@dbaeumer Thank you for the explanation. That explains why the code was so specifically scoped. Comparing VSCode 1.9 to the new behavior with this change, I do not see how this change is a regression however. For instance, with a javascript project: // test.es6
export const abc = 123 //index.js
import { abc } from './test' In VSCode 1.9, we do not generate any errors. The type of If we're working with TypeScript file instead ( After this change the errors are unchanged but now in the JavaScript case, we have more consistent behavior. Could you please explain your specific concerns a bit more or provide an example of where the behavior will be worse / more confusing? Also, here's the TS issue regarding custom file extensions: microsoft/TypeScript#10939 Seems like they've decided against supporting them for now |
The biggest problem I have are not only the errors (should have been more precise in my first comment) it is more about how we best explain this to users. So far we said: JS and TS smartness is only supported in .js, .ts, d.ts, .jsx and .tsx files. With one exception: files without an extension that have the JS mode (and thay was fishy too and we only did it for the script kind without extensions). Now one can open a .es6 file select a symbol and do |
@dbaeumer I agree that the behavior using custom file extensions is confusing, but I still struggling to understand how this change makes it worse. In VSCode 1.9, After this change, I see mostly the same behavior except that we now explicitly tell TypeScript that the file is a JavaScript file |
@mjbvz looks like I already made it worse a while ago then. At the beginning I tried to only provide TS / JS smartness for file extension the tsserver is aware of. Exactly to avoid the confusion and the bugs that are coming from it. |
http://stackoverflow.com/questions/42139118/is-error-checking-in-vs-code-exclusively-tied-to-the-file-extension
bug
When using custom file associations for js/ts files, we do not always open the files against TypeScript with the correct language mode.
Fix
Always send
scriptKind
to Typescript based on the languageId of the file