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

Commit

Permalink
Further work on FCS API (dotnet#10772)
Browse files Browse the repository at this point in the history
* trim API surface area

* move Range and Pos types to FSharp.Compiler

* undo uppercae range/pos

* move Range and Pos types to FSHarp.Compiler.SourceCodeServices since they are part of the FCS API

* fix baselines

* release notes

* FIX BUILD

* fix test

* fix test

* fix test

* fix test

* fix build

* fix build

* fix build

* PrettyNaming moved to SourceCodeServices

* ISourceText moved to SourceCodeServices

* update docs

* update docs

* fix build

* fix build

* move Range, Pos to FSharp.Compiler.Text

* fix test

* fix build

Co-authored-by: Don Syme <[email protected]>
  • Loading branch information
2 people authored and nosami committed Feb 22, 2021
1 parent 21307de commit 98e8a32
Show file tree
Hide file tree
Showing 64 changed files with 984 additions and 434 deletions.
82 changes: 41 additions & 41 deletions AutomaticCompletion/BraceCompletionSessionProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ type BraceCompletionSession
let mutable openingPoint : ITrackingPoint = null
let editorOperations = editorOperationsFactoryService.GetEditorOperations(textView)

member __.EndSession() =
member _.EndSession() =
closingPoint <- null
openingPoint <- null

member __.CreateUndoTransaction() =
member _.CreateUndoTransaction() =
undoHistory.CreateTransaction(BraceCompletion)

member this.Start (cancellationToken: CancellationToken) =
Expand Down Expand Up @@ -147,7 +147,7 @@ type BraceCompletionSession

undo.Complete()

member __.HasNoForwardTyping(caretPoint: SnapshotPoint, endPoint: SnapshotPoint) =
member _.HasNoForwardTyping(caretPoint: SnapshotPoint, endPoint: SnapshotPoint) =
Debug.Assert(caretPoint.Snapshot = endPoint.Snapshot, "snapshots do not match")

if caretPoint.Snapshot = endPoint.Snapshot then
Expand All @@ -172,7 +172,7 @@ type BraceCompletionSession
else
false

member __.MoveCaretToClosingPoint() =
member _.MoveCaretToClosingPoint() =
let closingSnapshotPoint = closingPoint.GetPoint(subjectBuffer.CurrentSnapshot)

// find the position just after the closing brace in the view's text buffer
Expand Down Expand Up @@ -216,7 +216,7 @@ type BraceCompletionSession
undo.Complete()
this.EndSession()

member __.PostBackspace() = ()
member _.PostBackspace() = ()

member this.PreOverType handledCommand =
handledCommand <- false
Expand Down Expand Up @@ -258,7 +258,7 @@ type BraceCompletionSession
undo.Complete()
| _ -> ()

member __.PostOverType() = ()
member _.PostOverType() = ()

member this.PreTab handledCommand =
handledCommand <- false
Expand All @@ -273,7 +273,7 @@ type BraceCompletionSession
editorOperations.AddAfterTextBufferChangePrimitive()
undo.Complete()

member __.PreReturn handledCommand =
member _.PreReturn handledCommand =
handledCommand <- false

member this.PostReturn() =
Expand All @@ -285,26 +285,26 @@ type BraceCompletionSession
session.AfterReturn(this, CancellationToken.None)
| _ -> ()

member __.Finish() = ()
member _.Finish() = ()

member __.PostTab() = ()
member _.PostTab() = ()

member __.PreDelete handledCommand =
member _.PreDelete handledCommand =
handledCommand <- false

member __.PostDelete() = ()
member _.PostDelete() = ()

member __.OpeningBrace = openingBrace
member _.OpeningBrace = openingBrace

member __.ClosingBrace = closingBrace
member _.ClosingBrace = closingBrace

member __.OpeningPoint = openingPoint
member _.OpeningPoint = openingPoint

member __.ClosingPoint = closingPoint
member _.ClosingPoint = closingPoint

member __.SubjectBuffer = subjectBuffer
member _.SubjectBuffer = subjectBuffer

member __.TextView = textView
member _.TextView = textView

module Parenthesis =

Expand Down Expand Up @@ -371,88 +371,88 @@ type ParenthesisCompletionSession() =

interface IEditorBraceCompletionSession with

member __.AfterReturn(_session, _cancellationToken) =
member _.AfterReturn(_session, _cancellationToken) =
()

member __.AfterStart(_session, _cancellationToken) =
member _.AfterStart(_session, _cancellationToken) =
()

member __.AllowOverType(_session, _cancellationToken) =
member _.AllowOverType(_session, _cancellationToken) =
true

member __.CheckOpeningPoint(_session, _cancellationToken) =
member _.CheckOpeningPoint(_session, _cancellationToken) =
true

type DoubleQuoteCompletionSession() =

interface IEditorBraceCompletionSession with

member __.AfterReturn(_session, _cancellationToken) =
member _.AfterReturn(_session, _cancellationToken) =
()

member __.AfterStart(_session, _cancellationToken) =
member _.AfterStart(_session, _cancellationToken) =
()

member __.AllowOverType(_session, _cancellationToken) =
member _.AllowOverType(_session, _cancellationToken) =
true

member __.CheckOpeningPoint(_session, _cancellationToken) =
member _.CheckOpeningPoint(_session, _cancellationToken) =
true

type VerticalBarCompletionSession() =

interface IEditorBraceCompletionSession with

member __.AfterReturn(_session, _cancellationToken) =
member _.AfterReturn(_session, _cancellationToken) =
()

member __.AfterStart(_session, _cancellationToken) =
member _.AfterStart(_session, _cancellationToken) =
()

member __.AllowOverType(_session, _cancellationToken) =
member _.AllowOverType(_session, _cancellationToken) =
true

(* This is for [| |] and {| |} , since the implementation deals with chars only.
We have to test if there is a { or [ before the cursor position and insert the closing '|'. *)
member __.CheckOpeningPoint(session, _cancellationToken) =
member _.CheckOpeningPoint(session, _cancellationToken) =
tryInsertAdditionalBracePair session CurlyBrackets.OpenCharacter CurlyBrackets.CloseCharacter ||
tryInsertAdditionalBracePair session SquareBrackets.OpenCharacter SquareBrackets.CloseCharacter

type AngleBracketCompletionSession() =

interface IEditorBraceCompletionSession with

member __.AfterReturn(_session, _cancellationToken) =
member _.AfterReturn(_session, _cancellationToken) =
()

member __.AfterStart(_session, _cancellationToken) =
member _.AfterStart(_session, _cancellationToken) =
()

member __.AllowOverType(_session, _cancellationToken) =
member _.AllowOverType(_session, _cancellationToken) =
true

(* This is for attributes [< >] , since the implementation deals with chars only.
We have to test if there is a [ before the cursor position and insert the closing '>'. *)
member __.CheckOpeningPoint(session, _cancellationToken) =
member _.CheckOpeningPoint(session, _cancellationToken) =
tryInsertAdditionalBracePair session SquareBrackets.OpenCharacter SquareBrackets.CloseCharacter

(* For multi-line comments, test if it is between "()" *)
type AsteriskCompletionSession() =

interface IEditorBraceCompletionSession with

member __.AfterReturn(_session, _cancellationToken) =
member _.AfterReturn(_session, _cancellationToken) =
()

member __.AfterStart(_session, _cancellationToken) =
member _.AfterStart(_session, _cancellationToken) =
()

member __.AllowOverType(_session, _cancellationToken) =
member _.AllowOverType(_session, _cancellationToken) =
true

(* This is for attributes [< >] , since the implementation deals with chars only.
We have to test if there is a [ before the cursor position and insert the closing '>'. *)
member __.CheckOpeningPoint(session, _cancellationToken) =
member _.CheckOpeningPoint(session, _cancellationToken) =
tryInsertAdditionalBracePair session Parenthesis.OpenCharacter Parenthesis.CloseCharacter

[<ExportLanguageService(typeof<IEditorBraceCompletionSessionFactory>, FSharpConstants.FSharpLanguageName)>]
Expand All @@ -464,14 +464,14 @@ type EditorBraceCompletionSessionFactory() =
| ClassificationTypeNames.StringLiteral -> false
| _ -> true

member __.IsSupportedOpeningBrace openingBrace =
member _.IsSupportedOpeningBrace openingBrace =
match openingBrace with
| Parenthesis.OpenCharacter | CurlyBrackets.OpenCharacter | SquareBrackets.OpenCharacter
| DoubleQuote.OpenCharacter | VerticalBar.OpenCharacter | AngleBrackets.OpenCharacter
| Asterisk.OpenCharacter -> true
| _ -> false

member __.CheckCodeContext(document: Document, position: int, _openingBrace:char, cancellationToken) =
member _.CheckCodeContext(document: Document, position: int, _openingBrace:char, cancellationToken) =
// We need to know if we are inside a F# string or comment. If we are, then don't do automatic completion.
let sourceCodeTask = document.GetTextAsync(cancellationToken)
sourceCodeTask.Wait(cancellationToken)
Expand Down Expand Up @@ -503,7 +503,7 @@ type EditorBraceCompletionSessionFactory() =
// classifiedSpan.TextSpan.IntersectsWith position &&
// not (spanIsString classifiedSpan)))))

member __.CreateEditorSession(_document, _openingPosition, openingBrace, _cancellationToken) =
member _.CreateEditorSession(_document, _openingPosition, openingBrace, _cancellationToken) =
match openingBrace with
| Parenthesis.OpenCharacter -> ParenthesisCompletionSession() :> IEditorBraceCompletionSession
| CurlyBrackets.OpenCharacter -> ParenthesisCompletionSession() :> IEditorBraceCompletionSession
Expand Down Expand Up @@ -540,7 +540,7 @@ type BraceCompletionSessionProvider

interface IBraceCompletionSessionProvider with

member __.TryCreateSession(textView, openingPoint, openingBrace, closingBrace, session) =
member _.TryCreateSession(textView, openingPoint, openingBrace, closingBrace, session) =
session <-
maybe {
let! document = openingPoint.Snapshot.GetOpenDocumentInCurrentContextWithChanges() |> Option.ofObj
Expand Down
2 changes: 1 addition & 1 deletion Build/SetGlobalPropertiesForSdkProjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ type internal SetGlobalPropertiesForSdkProjects
) =
inherit StaticGlobalPropertiesProviderBase(projectService.Services)

override __.GetGlobalPropertiesAsync(_cancellationToken: CancellationToken): Task<IImmutableDictionary<string, string>> =
override _.GetGlobalPropertiesAsync(_cancellationToken: CancellationToken): Task<IImmutableDictionary<string, string>> =
let properties = Empty.PropertiesMap.Add("FSharpCompilerPath", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
Task.FromResult<IImmutableDictionary<string, string>>(properties)
20 changes: 10 additions & 10 deletions Classification/ClassificationService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Classification

open Microsoft.CodeAnalysis
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.Text

// IEditorClassificationService is marked as Obsolete, but is still supported. The replacement (IClassificationService)
// is internal to Microsoft.CodeAnalysis.Workspaces which we don't have internals visible to. Rather than add yet another
// IVT, we'll maintain the status quo.
#nowarn "44"

#nowarn "57"

open Microsoft.CodeAnalysis
open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices

type SemanticClassificationData = (struct(FSharp.Compiler.Range.range * SemanticClassificationType)[])
type SemanticClassificationData = (struct(Range * SemanticClassificationType)[])
type SemanticClassificationLookup = IReadOnlyDictionary<int, ResizeArray<struct(range * SemanticClassificationType)>>

[<Sealed>]
Expand Down Expand Up @@ -118,7 +118,7 @@ type internal FSharpClassificationService
| _ -> ()

static let toSemanticClassificationLookup (data: SemanticClassificationData) =
let lookup = System.Collections.Generic.Dictionary<int, ResizeArray<struct(FSharp.Compiler.Range.range * SemanticClassificationType)>>()
let lookup = System.Collections.Generic.Dictionary<int, ResizeArray<struct(Range * SemanticClassificationType)>>()
for i = 0 to data.Length - 1 do
let (struct(r, _) as dataItem) = data.[i]
let items =
Expand All @@ -135,9 +135,9 @@ type internal FSharpClassificationService

interface IFSharpClassificationService with
// Do not perform classification if we don't have project options (#defines matter)
member __.AddLexicalClassifications(_: SourceText, _: TextSpan, _: List<ClassifiedSpan>, _: CancellationToken) = ()
member _.AddLexicalClassifications(_: SourceText, _: TextSpan, _: List<ClassifiedSpan>, _: CancellationToken) = ()

member __.AddSyntacticClassificationsAsync(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken) =
member _.AddSyntacticClassificationsAsync(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken) =
async {
use _logBlock = Logger.LogBlock(LogEditorFunctionId.Classification_Syntactic)

Expand All @@ -153,7 +153,7 @@ type internal FSharpClassificationService
result.AddRange(Tokenizer.getClassifiedSpans(document.Id, sourceText, textSpan, Some(document.FilePath), defines, cancellationToken))
} |> RoslynHelpers.StartAsyncUnitAsTask cancellationToken

member __.AddSemanticClassificationsAsync(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken) =
member _.AddSemanticClassificationsAsync(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken) =
asyncMaybe {
use _logBlock = Logger.LogBlock(LogEditorFunctionId.Classification_Semantic)

Expand Down Expand Up @@ -181,6 +181,6 @@ type internal FSharpClassificationService
|> Async.Ignore |> RoslynHelpers.StartAsyncUnitAsTask cancellationToken

// Do not perform classification if we don't have project options (#defines matter)
member __.AdjustStaleClassification(_: SourceText, classifiedSpan: ClassifiedSpan) : ClassifiedSpan = classifiedSpan
member _.AdjustStaleClassification(_: SourceText, classifiedSpan: ClassifiedSpan) : ClassifiedSpan = classifiedSpan


3 changes: 1 addition & 2 deletions CodeFix/AddOpenCodeFixProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions

open FSharp.Compiler
open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.Text

[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "AddOpen"); Shared>]
type internal FSharpAddOpenCodeFixProvider
Expand Down
2 changes: 1 addition & 1 deletion CodeFix/ChangeRefCellDerefToNotExpression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type internal FSharpChangeRefCellDerefToNotExpressionCodeFixProvider
static let userOpName = "FSharpChangeRefCellDerefToNotExpressionCodeFix"
let fixableDiagnosticIds = set ["FS0001"]

override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds

override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
Expand Down
2 changes: 1 addition & 1 deletion CodeFix/ChangeToUpcast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type internal FSharpChangeToUpcastCodeFixProvider() =

let fixableDiagnosticIds = set ["FS3198"]

override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds

override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
Expand Down
2 changes: 1 addition & 1 deletion CodeFix/ConvertToSingleEqualsEqualityExpression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type internal FSharpConvertToSingleEqualsEqualityExpressionCodeFixProvider() =

let fixableDiagnosticIds = set ["FS0043"]

override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds

override this.RegisterCodeFixesAsync context : Task =
asyncMaybe {
Expand Down
6 changes: 3 additions & 3 deletions CodeFix/ImplementInterfaceCodeFixProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions

open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.SyntaxTree
open FSharp.Compiler.Text

[<NoEquality; NoComparison>]
type internal InterfaceState =
Expand Down Expand Up @@ -133,9 +133,9 @@ type internal FSharpImplementInterfaceCodeFixProvider
else
()

override __.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds
override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds

override __.RegisterCodeFixesAsync context : Task =
override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(context.Document, context.CancellationToken, userOpName)
let cancellationToken = context.CancellationToken
Expand Down
2 changes: 1 addition & 1 deletion CodeFix/MakeDeclarationMutable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ open System.Threading.Tasks
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes

open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.Text

[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "MakeDeclarationMutable"); Shared>]
type internal FSharpMakeDeclarationMutableFixProvider
Expand Down
4 changes: 2 additions & 2 deletions CodeFix/MissingReferenceCodeFixProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type internal MissingReferenceCodeFixProvider() =
),
title)

override __.FixableDiagnosticIds = Seq.toImmutableArray [fixableDiagnosticId]
override _.FixableDiagnosticIds = Seq.toImmutableArray [fixableDiagnosticId]

override __.RegisterCodeFixesAsync context : Task =
override _.RegisterCodeFixesAsync context : Task =
async {
let solution = context.Document.Project.Solution

Expand Down
Loading

0 comments on commit 98e8a32

Please sign in to comment.