-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
There was a problem hiding this 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.
src/LanguageServer.ts
Outdated
return this.documentFileResolver(pathAbsolute); | ||
builder.addFileResolver({ | ||
readFile: (pathAbsolute) => this.documentFileResolver(pathAbsolute), | ||
readFileSync: (pathAbsolute) => this.documentFileResolver(pathAbsolute) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok makes sense.
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:
Program
,BrsFile
,XmlFile
.ProgramBuilder
still uses async logic when loading files because it yields a lot of performance benefits.fileResolver
logic out ofProgram
and intoProgramBuilder
so the language server can continue to use the in-memoryDocument
storesfileResolver
into an object withreadFile
andreadFileSync
functions so we can use the proper function when needed.fileExists
topathExists
andpathExistsSync
to line up with the ones fromfs-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.