Skip to content

Provide a way to determine whether a SourceFile is an untitled, inexistent file #37987

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

Closed
5 tasks done
neurolag opened this issue Apr 15, 2020 · 4 comments · Fixed by #38269
Closed
5 tasks done

Provide a way to determine whether a SourceFile is an untitled, inexistent file #37987

neurolag opened this issue Apr 15, 2020 · 4 comments · Fixed by #38269
Assignees
Labels
API Relates to the public API for TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this

Comments

@neurolag
Copy link
Contributor

Search Terms

tsserverlibrary, untitled, isdynamic

Suggestion

Currently I'm trying to write a language service for typescript and I find myself unable to determine whether a file is untitled.

What I've noticed so far is that untitled files send untitled:^Untitled-1 as its filename to the getSymanticDiagnostics function. This naming convention could change anytime and also it's not consistently containing an URI or a filepath.

Is there some way to check whether a SourceFile is untitled?

Use Cases

I'm passing the files to a linter. If the file is untitled I'll get an incorrect results if I pass the filename which, at runtime, equals untitled:^Untitled-1.

Examples

result = engine.executeOnText(file.getFullText(), ...(file.isUntitled ? [] : [file.fileName]));

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Apr 20, 2020
@RyanCavanaugh
Copy link
Member

@sheetalkamat is this a guaranteed format?

@sheetalkamat
Copy link
Member

We do not have any concept of untitiled files in program as it doesnt need to know but tsserver has isDynamicFileName that handles this to check if file needs to be checked on disk. In general any open file in editor may not exist on the disk since editor provides contents for the same.

@neurolag
Copy link
Contributor Author

Thanks for the rapid answer
I do not know whether this might be related to the @internal-tag but when I tried to look fot this method I found myself unable to find it

@sheetalkamat
Copy link
Member

It is marked as internal. I dont see issue with making it public. PR is welcome to remove internal.

@sheetalkamat sheetalkamat added API Relates to the public API for TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this and removed Needs Investigation This issue needs a team member to investigate its status. labels Apr 29, 2020
sheetalkamat pushed a commit that referenced this issue May 8, 2020
* Make isDynamicFileName available publicly

This commit fixes #37987

* Acknowledge Public APIs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants