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

Remove async file adding from program #278

Merged
merged 6 commits into from
Jan 19, 2021
Merged

Remove async file adding from program #278

merged 6 commits into from
Jan 19, 2021

Conversation

TwitchBronBron
Copy link
Member

Since the xml parser change removed the need for any async parsing, there's no benefit to having async file adding logic at all in the Program and downstream. Notable changes:

  • remove all unnecessary async functionality from Program, BrsFile, XmlFile.
  • The ProgramBuilder still uses async logic when loading files because it yields a lot of performance benefits.
  • Moved fileResolver logic out of Program and into ProgramBuilder so the language server can continue to use the in-memory Document stores
  • Changed fileResolver into an object with readFile and readFileSync functions so we can use the proper function when needed.
  • renamed fileExists to pathExists and pathExistsSync to line up with the ones from fs-extra

I broke the commits up so you can see just the raw api changes in this commit, and then all the unit tests in this commit.

Copy link
Contributor

@elsassph elsassph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally fine but added couple of questions.

return this.documentFileResolver(pathAbsolute);
builder.addFileResolver({
readFile: (pathAbsolute) => this.documentFileResolver(pathAbsolute),
readFileSync: (pathAbsolute) => this.documentFileResolver(pathAbsolute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum why it's all sync?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The language server protocol has a concept called TextDocument. Those objects are in-memory copies of the files. Basically every time you open a file, type in the file, etc, it gets streamed to the language server automatically and exists in memory. So there's nothing async to do with those.

src: change.pathAbsolute,
dest: rokuDeploy.getDestPath(change.pathAbsolute, options.files, rootDir)
});
if (await util.pathExists(change.pathAbsolute)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize: why do you test if the file physically exists instead of letting the file resolver(s) try to find it? Otherwise what's the point to the list of resolvers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file resolver concept was created to support the language server's TextDocument design. Generally you'll only have two resolvers: the language server, and then the actual file system. We read the language server first, and if not there, go to the file system.

Since our language server has a separate process to handle not-saved transient files (I call them standalone files), we can safely assume that all other files are physically located on disk, regardless of whether they are currently opened in the editor or not, so this check works just fine.

Unless I'm missing something, I don't see any need to modify the file resolvers to support doesFileExist logic since it doesn't seem to provide any benefit. Do you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok makes sense.

@TwitchBronBron TwitchBronBron merged commit 06d8dbe into master Jan 19, 2021
@TwitchBronBron TwitchBronBron deleted the remove-async branch January 19, 2021 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants