Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
Parsing improvements: no reactor, add parsing options, error severity…
Browse files Browse the repository at this point in the history
… options (dotnet#3601)

* Parse without reactor, add parsing options, error severity options

* Revert parsing APIs (fallback to the new ones), fix VFT projects

* Cache parse results after type check

* Add impl files to file check results (dotnet#3659)

* add LanguageServiceProfiling project to internals visible to list of FSharp.Compiler.Private project

* add ImplementationFiles to FSharpCheckFileResults

* make FSharpImplementationFileContents ctor internal

* throw if ImplementationFiles is called having keepAssemblyContents flag set to false

* add a test

* spelling and cosmetics

* This adds backup, restore, coloration and many more checks to the update-vsintegration.cmd (dotnet#3672)

* This adds backup, restore, coloration and many more checks to the update-vsintegration.cmd

* This adds backup, restore, coloration and many more checks to the update-vsintegration.cmd

* Remove ambiguous an irrelevant instruction, improved help and instructions

* Fix a scenario where the return code wasn't nonzero for error conditions, fixes not creating backup dir when not backing up

* add LanguageServiceProfiling project to internals visible to list of FSharp.Compiler.Private project (dotnet#3657)

* bump FCS version (dotnet#3676)

* bump version

* Update RELEASE_NOTES.md

* updates to make tests pass

* restore old behaviour of CheckFileInProjectAllowingStaleCachedResults (builder had been created by ParseFileInProject)

* restore use of CheckFileInProjectAllowingStaleCachedResults

* deprecate test relying on whacky behaviour of deprecated GetCheckResultsBeforeFileInProjectEvenIfStale

* Use ParseFile and FSharpParsingOptions instead of ParseFileInProject

* prepare FCS release with this feature
  • Loading branch information
auduchinok authored and dsyme committed Oct 3, 2017
1 parent 6728154 commit ab0426c
Show file tree
Hide file tree
Showing 28 changed files with 128 additions and 126 deletions.
4 changes: 2 additions & 2 deletions Classification/ColorizationService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ type internal FSharpColorizationService
asyncMaybe {
do Trace.TraceInformation("{0:n3} (start) SemanticColorization", DateTime.Now.TimeOfDay.TotalSeconds)
do! Async.Sleep DefaultTuning.SemanticColorizationInitialDelay |> liftAsync // be less intrusive, give other work priority most of the time
let! options = projectInfoManager.TryGetOptionsForDocumentOrProject(document)
let! _parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForDocumentOrProject(document)
let! sourceText = document.GetTextAsync(cancellationToken)
let! _, _, checkResults = checkerProvider.Checker.ParseAndCheckDocument(document, options, sourceText = sourceText, allowStaleResults = false, userOpName=userOpName)
let! _, _, checkResults = checkerProvider.Checker.ParseAndCheckDocument(document, projectOptions, sourceText = sourceText, allowStaleResults = false, userOpName=userOpName)
// it's crucial to not return duplicated or overlapping `ClassifiedSpan`s because Find Usages service crashes.
let targetRange = RoslynHelpers.TextSpanToFSharpRange(document.FilePath, textSpan, sourceText)
let colorizationData = checkResults.GetSemanticClassification (Some targetRange) |> Array.distinctBy fst
Expand Down
6 changes: 3 additions & 3 deletions CodeFix/AddOpenCodeFixProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ type internal FSharpAddOpenCodeFixProvider
override __.RegisterCodeFixesAsync context : Task =
asyncMaybe {
let document = context.Document
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
let! _, parsedInput, checkResults = checker.ParseAndCheckDocument(document, options, allowStaleResults = true, sourceText = sourceText, userOpName = userOpName)
let! _, parsedInput, checkResults = checker.ParseAndCheckDocument(document, projectOptions, allowStaleResults = true, sourceText = sourceText, userOpName = userOpName)
let line = sourceText.Lines.GetLineFromPosition(context.Span.End)
let linePos = sourceText.Lines.GetLinePosition(context.Span.End)
let defines = CompilerEnvironment.GetCompilationDefinesForEditing(document.Name, options.OtherOptions |> Seq.toList)
let defines = CompilerEnvironment.GetCompilationDefinesForEditing(document.Name, parsingOptions)

let! symbol =
asyncMaybe {
Expand Down
6 changes: 3 additions & 3 deletions CodeFix/ImplementInterfaceCodeFixProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ type internal FSharpImplementInterfaceCodeFixProvider

override __.RegisterCodeFixesAsync context : Task =
asyncMaybe {
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject context.Document
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject context.Document
let cancellationToken = context.CancellationToken
let! sourceText = context.Document.GetTextAsync(cancellationToken)
let! _, parsedInput, checkFileResults = checker.ParseAndCheckDocument(context.Document, options, sourceText = sourceText, allowStaleResults = true, userOpName = userOpName)
let! _, parsedInput, checkFileResults = checker.ParseAndCheckDocument(context.Document, projectOptions, sourceText = sourceText, allowStaleResults = true, userOpName = userOpName)
let textLine = sourceText.Lines.GetLineFromPosition context.Span.Start
let defines = CompilerEnvironment.GetCompilationDefinesForEditing(context.Document.FilePath, options.OtherOptions |> Seq.toList)
let defines = CompilerEnvironment.GetCompilationDefinesForEditing(context.Document.FilePath, parsingOptions)
// Notice that context.Span doesn't return reliable ranges to find tokens at exact positions.
// That's why we tokenize the line and try to find the last successive identifier token
let tokens = Tokenizer.tokenizeLine(context.Document.Id, sourceText, context.Span.Start, context.Document.FilePath, defines)
Expand Down
4 changes: 2 additions & 2 deletions CodeFix/RemoveUnusedOpens.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type internal FSharpRemoveUnusedOpensCodeFixProvider
let document = context.Document
let! sourceText = document.GetTextAsync()
let checker = checkerProvider.Checker
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! unusedOpens = UnusedOpensDiagnosticAnalyzer.GetUnusedOpenRanges(document, options, checker)
let! _parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! unusedOpens = UnusedOpensDiagnosticAnalyzer.GetUnusedOpenRanges(document, projectOptions, checker)
let changes =
unusedOpens
|> List.map (fun m ->
Expand Down
6 changes: 3 additions & 3 deletions CodeFix/RenameUnusedValue.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ type internal FSharpRenameUnusedValueCodeFixProvider
// We have to use the additional check for backtickes because `IsOperatorOrBacktickedName` operates on display names
// where backtickes are replaced with parens.
if not (PrettyNaming.IsOperatorOrBacktickedName ident) && not (ident.StartsWith "``") then
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
let! _, _, checkResults = checker.ParseAndCheckDocument(document, options, allowStaleResults = true, sourceText = sourceText, userOpName=userOpName)
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
let! _, _, checkResults = checker.ParseAndCheckDocument(document, projectOptions, allowStaleResults = true, sourceText = sourceText, userOpName=userOpName)
let m = RoslynHelpers.TextSpanToFSharpRange(document.FilePath, context.Span, sourceText)
let defines = CompilerEnvironment.GetCompilationDefinesForEditing (document.FilePath, options.OtherOptions |> Seq.toList)
let defines = CompilerEnvironment.GetCompilationDefinesForEditing (document.FilePath, parsingOptions)
let! lexerSymbol = Tokenizer.getSymbolAtPosition (document.Id, sourceText, context.Span.Start, document.FilePath, defines, SymbolLookupKind.Greedy, false)
let lineText = (sourceText.Lines.GetLineFromPosition context.Span.Start).ToString()
let! symbolUse = checkResults.GetSymbolUseAtLocation(m.StartLine, m.EndColumn, lineText, lexerSymbol.FullIsland, userOpName=userOpName)
Expand Down
4 changes: 2 additions & 2 deletions Commands/HelpContextService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ type internal FSharpHelpContextService

member this.GetHelpTermAsync(document, textSpan, cancellationToken) =
asyncMaybe {
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! _parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! sourceText = document.GetTextAsync(cancellationToken)
let! textVersion = document.GetTextVersionAsync(cancellationToken)
let defines = projectInfoManager.GetCompilationDefinesForEditingDocument(document)
let textLine = sourceText.Lines.GetLineFromPosition(textSpan.Start)
let tokens = Tokenizer.getColorizationData(document.Id, sourceText, textLine.Span, Some document.Name, defines, cancellationToken)
return! FSharpHelpContextService.GetHelpTerm(checkerProvider.Checker, sourceText, document.FilePath, options, textSpan, tokens, textVersion.GetHashCode())
return! FSharpHelpContextService.GetHelpTerm(checkerProvider.Checker, sourceText, document.FilePath, projectOptions, textSpan, tokens, textVersion.GetHashCode())
}
|> Async.map (Option.defaultValue "")
|> RoslynHelpers.StartAsyncAsTask cancellationToken
Expand Down
4 changes: 2 additions & 2 deletions Commands/XmlDocCommandService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ type internal XmlDocCommandFilter
// XmlDocable line #1 are 1-based, editor is 0-based
let curLineNum = wpfTextView.Caret.Position.BufferPosition.GetContainingLine().LineNumber + 1
let! document = document.Value
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! parsingOptions, _options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let sourceText = wpfTextView.TextBuffer.CurrentSnapshot.GetText()
let! parsedInput = checker.ParseDocument(document, options, sourceText, userOpName)
let! parsedInput = checker.ParseDocument(document, parsingOptions, sourceText, userOpName)
let xmlDocables = XmlDocParser.getXmlDocables (sourceText, Some parsedInput)
let xmlDocablesBelowThisLine =
// +1 because looking below current line for e.g. a 'member'
Expand Down
10 changes: 5 additions & 5 deletions Completion/CompletionProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ type internal FSharpCompletionProvider
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
let defines = projectInfoManager.GetCompilationDefinesForEditingDocument(document)
do! Option.guard (CompletionUtils.shouldProvideCompletion(document.Id, document.FilePath, defines, sourceText, context.Position))
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! _parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! textVersion = context.Document.GetTextVersionAsync(context.CancellationToken)
let! _, _, fileCheckResults = checker.ParseAndCheckDocument(document, options, true, userOpName=userOpName)
let! _, _, fileCheckResults = checker.ParseAndCheckDocument(document, projectOptions, true, userOpName=userOpName)
let getAllSymbols() =
if Settings.IntelliSense.ShowAllSymbols
then assemblyContentProvider.GetAllEntitiesInProjectAndReferencedAssemblies(fileCheckResults)
else []
let! results =
FSharpCompletionProvider.ProvideCompletionsAsyncAux(checker, sourceText, context.Position, options,
FSharpCompletionProvider.ProvideCompletionsAsyncAux(checker, sourceText, context.Position, projectOptions,
document.FilePath, textVersion.GetHashCode(), getAllSymbols)
context.AddItems(results)
} |> Async.Ignore |> RoslynHelpers.StartAsyncUnitAsTask context.CancellationToken
Expand Down Expand Up @@ -268,8 +268,8 @@ type internal FSharpCompletionProvider
let! sourceText = document.GetTextAsync(cancellationToken)
let textWithItemCommitted = sourceText.WithChanges(TextChange(item.Span, nameInCode))
let line = sourceText.Lines.GetLineFromPosition(item.Span.Start)
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! parsedInput = checker.ParseDocument(document, options, sourceText, userOpName)
let! parsingOptions, _options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! parsedInput = checker.ParseDocument(document, parsingOptions, sourceText, userOpName)
let fullNameIdents = fullName |> Option.map (fun x -> x.Split '.') |> Option.defaultValue [||]

let insertionPoint =
Expand Down
4 changes: 2 additions & 2 deletions Completion/SignatureHelp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ type internal FSharpSignatureHelpProvider
member this.GetItemsAsync(document, position, triggerInfo, cancellationToken) =
asyncMaybe {
try
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! _parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! sourceText = document.GetTextAsync(cancellationToken)
let! textVersion = document.GetTextVersionAsync(cancellationToken)

Expand All @@ -206,7 +206,7 @@ type internal FSharpSignatureHelpProvider
else None

let! (results,applicableSpan,argumentIndex,argumentCount,argumentName) =
FSharpSignatureHelpProvider.ProvideMethodsAsyncAux(checkerProvider.Checker, documentationBuilder, sourceText, position, options, triggerTypedChar, document.FilePath, textVersion.GetHashCode())
FSharpSignatureHelpProvider.ProvideMethodsAsyncAux(checkerProvider.Checker, documentationBuilder, sourceText, position, projectOptions, triggerTypedChar, document.FilePath, textVersion.GetHashCode())
let items =
results
|> Array.map (fun (hasParamArrayArg, doc, prefixParts, separatorParts, suffixParts, parameters, descriptionParts) ->
Expand Down
13 changes: 4 additions & 9 deletions Debugging/BreakpointResolutionService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ type internal FSharpBreakpointResolutionService
) =

static let userOpName = "BreakpointResolution"
static member GetBreakpointLocation(checker: FSharpChecker, sourceText: SourceText, fileName: string, textSpan: TextSpan, options: FSharpProjectOptions) =
static member GetBreakpointLocation(checker: FSharpChecker, sourceText: SourceText, fileName: string, textSpan: TextSpan, parsingOptions: FSharpParsingOptions) =
async {
// REVIEW: ParseFileInProject can cause FSharp.Compiler.Service to become unavailable (i.e. not responding to requests) for
// an arbitrarily long time while it parses all files prior to this one in the project (plus dependent projects if we enable
// cross-project checking in multi-project solutions). FCS will not respond to other
// requests unless this task is cancelled. We need to check that this task is cancelled in a timely way by the
// Roslyn UI machinery.
let textLinePos = sourceText.Lines.GetLinePosition(textSpan.Start)
let textInLine = sourceText.GetSubText(sourceText.Lines.[textLinePos.Line].Span).ToString()

Expand All @@ -42,16 +37,16 @@ type internal FSharpBreakpointResolutionService
else
let textLineColumn = textLinePos.Character
let fcsTextLineNumber = Line.fromZ textLinePos.Line // Roslyn line numbers are zero-based, FSharp.Compiler.Service line numbers are 1-based
let! parseResults = checker.ParseFileInProject(fileName, sourceText.ToString(), options, userOpName = userOpName)
let! parseResults = checker.ParseFile(fileName, sourceText.ToString(), parsingOptions, userOpName = userOpName)
return parseResults.ValidateBreakpointLocation(mkPos fcsTextLineNumber textLineColumn)
}

interface IBreakpointResolutionService with
member this.ResolveBreakpointAsync(document: Document, textSpan: TextSpan, cancellationToken: CancellationToken): Task<BreakpointResolutionResult> =
asyncMaybe {
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! parsingOptions, _options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! sourceText = document.GetTextAsync(cancellationToken)
let! range = FSharpBreakpointResolutionService.GetBreakpointLocation(checkerProvider.Checker, sourceText, document.Name, textSpan, options)
let! range = FSharpBreakpointResolutionService.GetBreakpointLocation(checkerProvider.Checker, sourceText, document.Name, textSpan, parsingOptions)
let! span = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, range)
return BreakpointResolutionResult.CreateSpanResult(document, span)
}
Expand Down
12 changes: 6 additions & 6 deletions Diagnostics/DocumentDiagnosticAnalyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
hash
}

static member GetDiagnostics(checker: FSharpChecker, filePath: string, sourceText: SourceText, textVersionHash: int, options: FSharpProjectOptions, diagnosticType: DiagnosticsType) =
static member GetDiagnostics(checker: FSharpChecker, filePath: string, sourceText: SourceText, textVersionHash: int, parsingOptions: FSharpParsingOptions, options: FSharpProjectOptions, diagnosticType: DiagnosticsType) =
async {
let! parseResults = checker.ParseFileInProject(filePath, sourceText.ToString(), options, userOpName=userOpName)
let! parseResults = checker.ParseFile(filePath, sourceText.ToString(), parsingOptions, userOpName=userOpName)
let! errors =
async {
match diagnosticType with
Expand Down Expand Up @@ -109,11 +109,11 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
override this.AnalyzeSyntaxAsync(document: Document, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
let projectInfoManager = getProjectInfoManager document
asyncMaybe {
let! options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
let! sourceText = document.GetTextAsync(cancellationToken)
let! textVersion = document.GetTextVersionAsync(cancellationToken)
return!
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(getChecker document, document.FilePath, sourceText, textVersion.GetHashCode(), options, DiagnosticsType.Syntax)
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(getChecker document, document.FilePath, sourceText, textVersion.GetHashCode(), parsingOptions, projectOptions, DiagnosticsType.Syntax)
|> liftAsync
}
|> Async.map (Option.defaultValue ImmutableArray<Diagnostic>.Empty)
Expand All @@ -122,11 +122,11 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
override this.AnalyzeSemanticsAsync(document: Document, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
let projectInfoManager = getProjectInfoManager document
asyncMaybe {
let! options = projectInfoManager.TryGetOptionsForDocumentOrProject(document)
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForDocumentOrProject(document)
let! sourceText = document.GetTextAsync(cancellationToken)
let! textVersion = document.GetTextVersionAsync(cancellationToken)
return!
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(getChecker document, document.FilePath, sourceText, textVersion.GetHashCode(), options, DiagnosticsType.Semantic)
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(getChecker document, document.FilePath, sourceText, textVersion.GetHashCode(), parsingOptions, projectOptions, DiagnosticsType.Semantic)
|> liftAsync
}
|> Async.map (Option.defaultValue ImmutableArray<Diagnostic>.Empty)
Expand Down
Loading

0 comments on commit ab0426c

Please sign in to comment.