Skip to content

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

Closed

Description

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.

Activity

  1. RyanCavanaugh commented on Apr 20, 2020

    @RyanCavanaugh
    Member

    Sheetal Nandi (@sheetalkamat) is this a guaranteed format?

  2. sheetalkamat commented on Apr 20, 2020

    @sheetalkamat
    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.

  3. neurolag commented on Apr 20, 2020

    @neurolag
    ContributorAuthor

    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

  4. sheetalkamat commented on Apr 29, 2020

    @sheetalkamat
    Member

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

  5. added
    Domain: APIRelates to the public API for TypeScript
    Good First IssueWell scoped, documented and has the green light
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Apr 29, 2020
  6. added a commit that references this issue on May 8, 2020
    cbc959b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Domain: APIRelates to the public API for TypeScriptGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions