Refactor AdaptiveServerState.forceFindOpenFileOrRead #1208
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WHAT
🤖[deprecated] Generated by Copilot at 5501b05
The pull request simplifies the error handling of various functions and methods in the FsAutoComplete project by using
option
andasyncOption
types instead ofResult
andResultOrString
types. This avoids unnecessary wrapping and unwrapping of results and allows returning more informative error messages. The pull request affects the filessrc/FsAutoComplete.Core/Commands.fs
,src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
,src/FsAutoComplete/LspServers/AdaptiveServerState.fs
,src/FsAutoComplete/CodeFixes.fs
,src/FsAutoComplete/CodeFixes.fsi
, and several files in thesrc/FsAutoComplete/CodeFixes
folder.🤖[deprecated] Generated by Copilot at 5501b05
📄🛠️🚀
WHY
This function was being used as a Result type and often times being converted to an option type. Since the function either was opened or it wasn't, I felt this refactor expresses the intent more clearly. It think it also allows the higher order functions to "think" more on what better error messages could be, rather than passing the "could not read file" up the pipeline.
HOW
🤖[deprecated] Generated by Copilot at 5501b05
Result
oroption
types by using theasyncResultOption
workflow in theAdaptiveFSharpLspServer
module (link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link)tryGetFileCheckerOptionsWithLines
parameter from a function that returns anAsync<Result<IFSACSourceText, _>>
to a function that returns anAsync<IFSACSourceText option>
in theCommands
module, and handle the case where the function returnsNone
by returning an error message with the file name (link, link, link, link, link)tryGetFileSource
parameter from a function that returns anAsync<ResultOrString<IFSACSourceText>>
to a function that returns anAsync<IFSACSourceText option>
in theCommands
module, and handle the case where the function returnsNone
by returning an error message with the file name and a flag to indicate whether the error should be fatal or not (link, link, link)GetFileLines
alias from a function that returns anAsync<ResultOrString<IFSACSourceText>>
to a function that returns anAsync<IFSACSourceText option>
in theCodeFixes
module, and handle the case where the function returnsNone
by returning an error message with the file name in the code fixes (link, link, link, link, link, link, link, link)forceFindOpenFileOrRead
function totryForceFindOpenFileOrRead
in theAdaptiveServerState
module, and handle the case where the function returnsNone
by returning an error message with the file name or using theasyncOption
workflow (link, link, link, link, link, link, link, link, link)GetOpenFileOrRead
method fromAsync<Result<VolatileFile, string>>
toAsync<VolatileFile option>
in theAdaptiveServerState
module, and handle the case where the method returnsNone
by returning an error message with the file name or using theasyncOption
workflow (link, link, link, link, link, link, link, link, link, link)Note
I also updated FsToolkit.ErrorHandling to the latest version