Skip to content

Commit

Permalink
incorporate cleanup related to analyzers (dotnet#11151)
Browse files Browse the repository at this point in the history
* incorporate cleanup related to analyzers

* fix error regressions

Co-authored-by: Don Syme <donsyme@fastmail.com>
  • Loading branch information
dsyme and Don Syme committed Feb 26, 2021
1 parent ef1cb67 commit 8ddb9e4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Commands/XmlDocCommandService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type internal XmlDocCommandFilter
let! parsingOptions, _options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, CancellationToken.None, userOpName)
let! sourceText = document.GetTextAsync(CancellationToken.None)
let! parsedInput = checker.ParseDocument(document, parsingOptions, sourceText, userOpName)
let xmlDocables = XmlDocParser.GetXmlDocables (sourceText.ToFSharpSourceText(), Some parsedInput)
let xmlDocables = XmlDocParser.GetXmlDocables (sourceText.ToFSharpSourceText(), parsedInput)
let xmlDocablesBelowThisLine =
// +1 because looking below current line for e.g. a 'member'
xmlDocables |> List.filter (fun (XmlDocable(line,_indent,_paramNames)) -> line = curLineNum+1)
Expand Down
9 changes: 7 additions & 2 deletions Common/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,15 @@ module internal RoslynHelpers =
// (i.e the same error does not appear twice, where the only difference is the line endings.)
let normalizedMessage = error.Message |> FSharpDiagnostic.NormalizeErrorString |> FSharpDiagnostic.NewlineifyErrorString

let id = "FS" + error.ErrorNumber.ToString("0000")
let id = error.ErrorNumberText
let emptyString = LocalizableString.op_Implicit("")
let description = LocalizableString.op_Implicit(normalizedMessage)
let severity = if error.Severity = FSharpDiagnosticSeverity.Error then DiagnosticSeverity.Error else DiagnosticSeverity.Warning
let severity =
match error.Severity with
| FSharpDiagnosticSeverity.Error -> DiagnosticSeverity.Error
| FSharpDiagnosticSeverity.Warning -> DiagnosticSeverity.Warning
| FSharpDiagnosticSeverity.Info -> DiagnosticSeverity.Info
| FSharpDiagnosticSeverity.Hidden -> DiagnosticSeverity.Hidden
let customTags =
match error.ErrorNumber with
| 1182 -> FSharpDiagnosticCustomTags.Unnecessary
Expand Down
5 changes: 1 addition & 4 deletions Completion/CompletionProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,7 @@ type internal FSharpCompletionProvider


if results.Count > 0 && not declarations.IsForType && not declarations.IsError && List.isEmpty partialName.QualifyingIdents then
let completionContext =
parseResults.ParseTree
|> Option.bind (fun parseTree ->
ParsedInput.TryGetCompletionContext(Position.fromZ caretLinePos.Line caretLinePos.Character, parseTree, line))
let completionContext = ParsedInput.TryGetCompletionContext(Position.fromZ caretLinePos.Line caretLinePos.Character, parseResults.ParseTree, line)

match completionContext with
| None -> results.AddRange(keywordCompletionItems)
Expand Down
6 changes: 2 additions & 4 deletions LanguageService/FSharpCheckerExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type FSharpChecker with
member checker.ParseDocument(document: Document, parsingOptions: FSharpParsingOptions, sourceText: SourceText, userOpName: string) =
asyncMaybe {
let! fileParseResults = checker.ParseFile(document.FilePath, sourceText.ToFSharpSourceText(), parsingOptions, userOpName=userOpName) |> liftAsync
return! fileParseResults.ParseTree
return fileParseResults.ParseTree
}

member checker.ParseAndCheckDocument(filePath: string, textVersionHash: int, sourceText: SourceText, options: FSharpProjectOptions, languageServicePerformanceOptions: LanguageServicePerformanceOptions, userOpName: string) =
Expand Down Expand Up @@ -40,9 +40,7 @@ type FSharpChecker with
let bindParsedInput(results: (FSharpParseFileResults * FSharpCheckFileResults) option) =
match results with
| Some(parseResults, checkResults) ->
match parseResults.ParseTree with
| Some parsedInput -> Some (parseResults, parsedInput, checkResults)
| None -> None
Some (parseResults, parseResults.ParseTree, checkResults)
| None -> None

if languageServicePerformanceOptions.AllowStaleCompletionResults then
Expand Down
23 changes: 11 additions & 12 deletions Navigation/NavigateToSearchService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,17 @@ type internal FSharpNavigateToSearchService
NavigateTo.GetNavigableItems parsedInput
|> Array.filter (fun i -> kinds.Contains(navigateToItemKindToRoslynKind i.Kind))

return
match parseResults.ParseTree |> Option.map navItems with
| Some items ->
[| for item in items do
match RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, item.Range) with
| None -> ()
| Some sourceSpan ->
let glyph = navigateToItemKindToGlyph item.Kind
let kind = navigateToItemKindToRoslynKind item.Kind
let additionalInfo = containerToString item.Container document.Project
yield NavigableItem(document, sourceSpan, glyph, item.Name, kind, additionalInfo) |]
| None -> [||]
let items = parseResults.ParseTree |> navItems
let navigableItems =
[| for item in items do
match RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, item.Range) with
| None -> ()
| Some sourceSpan ->
let glyph = navigateToItemKindToGlyph item.Kind
let kind = navigateToItemKindToRoslynKind item.Kind
let additionalInfo = containerToString item.Container document.Project
yield NavigableItem(document, sourceSpan, glyph, item.Name, kind, additionalInfo) |]
return navigableItems
}

let getCachedIndexedNavigableItems(document: Document, parsingOptions: FSharpParsingOptions, kinds: IImmutableSet<string>) =
Expand Down

0 comments on commit 8ddb9e4

Please sign in to comment.