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

make handling fantomas errors a bit safer by explicitly using the old source code #823

Merged
merged 1 commit into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,14 @@ type Commands (checker: FSharpCompilerServiceChecker, state: State, backgroundSe
| None ->
fantomasLogger.warn (Log.setMessage "No fantomas configuration found for file '{filePath}' or parent directories. Using the default configuration." >> Log.addContextDestructured "filePath" file)
Fantomas.FormatConfig.FormatConfig.Default
let! formatted = Fantomas.CodeFormatter.FormatDocumentAsync(UMX.untag file, Fantomas.SourceOrigin.SourceText text, config, parsingOptions, checker)
return text, formatted
try
let! formatted = Fantomas.CodeFormatter.FormatDocumentAsync(UMX.untag file, Fantomas.SourceOrigin.SourceText text, config, parsingOptions, checker)
return text, formatted
with
| ex ->
fantomasLogger.warn (Log.setMessage "Errors while formatting file, defaulting to previous content. Error message was {message}" >> Log.addContextDestructured "message" ex.Message >> Log.addExn ex)
return! Core.Error ex.Message
}
|> AsyncResult.foldResult Some (fun _ -> None)

/// gets the semantic classification ranges for a file, optionally filtered by a given range.
member x.GetHighlighting (file: string<LocalPath>, range: Range option) =
Expand Down
6 changes: 3 additions & 3 deletions src/FsAutoComplete/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,15 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
let fileName = doc.GetFilePath() |> Utils.normalizePath
let! res = commands.FormatDocument fileName
match res with
| Some (lines, formatted) ->
| Ok (lines, formatted) ->
let range =
let zero = { Line = 0; Character = 0 }
let lastPos = lines.GetLastFilePosition()
{ Start = zero; End = fcsPosToLsp lastPos }

return LspResult.success(Some([| { Range = range; NewText = formatted } |]))
| None ->
return LspResult.notImplemented
| Error ex ->
return LspResult.internalError ex
}

member private x.HandleTypeCheckCodeAction file pos f =
Expand Down