Skip to content

Commit

Permalink
Roslyn Shim - First Phase (#6498)
Browse files Browse the repository at this point in the history
* Trying to use shim

* Removed contenttypelangservice, it's in externalaccess now

* Added namespace

* Added diagnosticanalyzerservice shim

* Using Brace matching from external access

* Using VSWorkspace extensions

* More apis

* Using shim for IEditorFormattingService

* More apis

* More shims

* Updating shim

* Update VisualFSharp.UnitTests.fsproj

* Fixed api call

* Fix debugging

* Fixed unit test fsproj, find all refs shimmed

* Change analyserservice

* Fixed build

* Updating shim with FSharp prefixes

* Fixing glyph helpers

* Fixing typemap

* Update fsi.fsproj

* Update Versions.props

* Update RoslynPackageVersion.txt

* Update prim-lexing.fs

* Update prim-lexing.fs

* Update fsi.fsproj

* Update fsi.fsproj

* Update VisualFSharp.UnitTests.fsproj

* Update CompletionProvider.fs

* Fixed package
  • Loading branch information
TIHan authored and brettfo committed Apr 23, 2019
1 parent 69539f2 commit a5510fb
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 76 deletions.
2 changes: 1 addition & 1 deletion RoslynPackageVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-beta4-19170-01
3.1.0-beta3-19222-02
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/F/roslyn/api/v3/index.json;
https://dotnet.myget.org/F/symreader-converter/api/v3/index.json;
https://dotnet.myget.org/F/interactive-window/api/v3/index.json;
https://myget.org/F/vs-devcore/api/v3/index.json;
https://myget.org/F/vs-editor/api/v3/index.json;
https://vside.myget.org/F/vssdk/api/v3/index.json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ open Microsoft.CodeAnalysis.Classification
open Microsoft.CodeAnalysis.Editor
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Classification

// 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
Expand All @@ -21,7 +22,7 @@ open Microsoft.CodeAnalysis.Text

open FSharp.Compiler.SourceCodeServices

[<ExportLanguageService(typeof<IEditorClassificationService>, FSharpConstants.FSharpLanguageName)>]
[<Export(typeof<IFSharpClassificationService>)>]
type internal FSharpClassificationService
[<ImportingConstructor>]
(
Expand All @@ -30,7 +31,7 @@ type internal FSharpClassificationService
) =
static let userOpName = "SemanticColorization"

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

Expand Down
3 changes: 2 additions & 1 deletion vsintegration/src/FSharp.Editor/CodeLens/CodeLensProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ open Microsoft.VisualStudio.Text.Classification
open Microsoft.VisualStudio.ComponentModelHost
open System.Threading
open Microsoft.VisualStudio.FSharp.Editor.Logging
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor.Shared.Utilities

[<Export(typeof<IWpfTextViewCreationListener>)>]
[<Export(typeof<IViewTaggerProvider>)>]
Expand All @@ -32,7 +33,7 @@ type internal CodeLensProvider
textDocumentFactory: ITextDocumentFactoryService,
checkerProvider: FSharpCheckerProvider,
projectInfoManager: FSharpProjectOptionsManager,
typeMap : ClassificationTypeMap Lazy,
typeMap : FSharpClassificationTypeMap Lazy,
settings: EditorOptions
) =

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Editor.Shared.Extensions
open Microsoft.CodeAnalysis.Editor.Shared.Utilities
open Microsoft.CodeAnalysis.Classification
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Classification

open FSharp.Compiler
open FSharp.Compiler.Ast
Expand All @@ -31,6 +32,8 @@ open Microsoft.VisualStudio.Text.Formatting

open Internal.Utilities.StructuredFormat

open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor.Shared.Utilities

type internal CodeLens(taggedText, computed, fullTypeSignature, uiElement) =
member val TaggedText: Async<(ResizeArray<Layout.TaggedText> * QuickInfoNavigation) option> = taggedText
member val Computed: bool = computed with get, set
Expand All @@ -46,7 +49,7 @@ type internal FSharpCodeLensService
checker: FSharpChecker,
projectInfoManager: FSharpProjectOptionsManager,
classificationFormatMapService: IClassificationFormatMapService,
typeMap: Lazy<ClassificationTypeMap>,
typeMap: Lazy<FSharpClassificationTypeMap>,
codeLens : CodeLensDisplayService,
settings: EditorOptions
) as self =
Expand Down Expand Up @@ -78,7 +81,7 @@ type internal FSharpCodeLensService
let layoutTagToFormatting (layoutTag: LayoutTag) =
layoutTag
|> RoslynHelpers.roslynTag
|> ClassificationTags.GetClassificationTypeName
|> FSharpClassificationTags.GetClassificationTypeName
|> typeMap.Value.GetClassificationType
|> formatMap.Value.GetTextProperties

Expand Down
9 changes: 1 addition & 8 deletions vsintegration/src/FSharp.Editor/Common/ContentType.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open System.ComponentModel.Composition

open Microsoft.CodeAnalysis.Editor
open Microsoft.VisualStudio.Utilities
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor

module FSharpStaticTypeDefinitions =
[<Export>]
Expand All @@ -17,11 +18,3 @@ module FSharpStaticTypeDefinitions =
[<Name(FSharpConstants.FSharpSignatureHelpContentTypeName)>]
[<BaseDefinition("sighelp")>]
let FSharpSignatureHelpContentTypeDefinition = ContentTypeDefinition()

[<ExportContentTypeLanguageService(FSharpConstants.FSharpContentTypeName, FSharpConstants.FSharpLanguageName)>]
type FSharpContentType [<System.Composition.ImportingConstructor>](contentTypeRegistry : IContentTypeRegistryService) =
member this.contentTypeRegistryService = contentTypeRegistry

interface IContentTypeLanguageService with
member this.GetDefaultContentType() =
this.contentTypeRegistryService.GetContentType(FSharpConstants.FSharpContentTypeName)
4 changes: 4 additions & 0 deletions vsintegration/src/FSharp.Editor/Common/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ open Microsoft.CodeAnalysis.Host
open FSharp.Compiler.Text
open FSharp.Compiler.Ast
open FSharp.Compiler.SourceCodeServices
open Microsoft.CodeAnalysis.ExternalAccess.FSharp

type private FSharpGlyph = FSharp.Compiler.SourceCodeServices.FSharpGlyph
type private Glyph = Microsoft.CodeAnalysis.ExternalAccess.FSharp.FSharpGlyph


type Path with
Expand Down
3 changes: 2 additions & 1 deletion vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open FSharp.Compiler.Layout
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.Range
open Microsoft.VisualStudio.FSharp.Editor.Logging
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics

[<RequireQualifiedAccess>]
module internal RoslynHelpers =
Expand Down Expand Up @@ -149,7 +150,7 @@ module internal RoslynHelpers =
let severity = if error.Severity = FSharpErrorSeverity.Error then DiagnosticSeverity.Error else DiagnosticSeverity.Warning
let customTags =
match error.ErrorNumber with
| 1182 -> DiagnosticCustomTags.Unnecessary
| 1182 -> FSharpDiagnosticCustomTags.Unnecessary
| _ -> null
let descriptor = new DiagnosticDescriptor(id, emptyString, description, error.Subcategory, severity, true, emptyString, String.Empty, customTags)
Diagnostic.Create(descriptor, location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ type internal FSharpCompletionProvider
| _, idents -> Array.last idents

let completionItem =
CommonCompletionItem.Create(name, null, glyph = Nullable glyph, rules = getRules intellisenseOptions.ShowAfterCharIsTyped, filterText = filterText)
CommonCompletionItem.Create(name, null, rules = getRules intellisenseOptions.ShowAfterCharIsTyped, glyph = Nullable (Microsoft.CodeAnalysis.ExternalAccess.FSharp.FSharpGlyphHelpersObsolete.Convert(glyph)), filterText = filterText)
.AddProperty(FullNamePropName, declarationItem.FullName)

let completionItem =
Expand Down Expand Up @@ -303,4 +303,4 @@ type internal FSharpCompletionProvider
}
|> Async.map (Option.defaultValue (CompletionChange.Create(TextChange(item.Span, nameInCode))))

} |> RoslynHelpers.StartAsyncAsTask cancellationToken
} |> RoslynHelpers.StartAsyncAsTask cancellationToken
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ type internal HashDirectiveCompletionProvider(workspace: Workspace, projectInfoM
rules)

let pathThroughLastSlash = getPathThroughLastSlash(text, position, quotedPathGroup)
context.AddItems(helper.GetItems(pathThroughLastSlash, ct))
let! items = helper.GetItemsAsync(pathThroughLastSlash, ct) |> Async.AwaitTask |> liftAsync
context.AddItems(items)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask context.CancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Editor.Implementation.Debugging
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor.Implementation.Debugging

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

[<Shared>]
[<ExportLanguageService(typeof<IBreakpointResolutionService>, FSharpConstants.FSharpLanguageName)>]
[<Export(typeof<IFSharpBreakpointResolutionService>)>]
type internal FSharpBreakpointResolutionService
[<ImportingConstructor>]
(
Expand All @@ -41,18 +41,18 @@ type internal FSharpBreakpointResolutionService
return parseResults.ValidateBreakpointLocation(mkPos fcsTextLineNumber textLineColumn)
}

interface IBreakpointResolutionService with
member this.ResolveBreakpointAsync(document: Document, textSpan: TextSpan, cancellationToken: CancellationToken): Task<BreakpointResolutionResult> =
interface IFSharpBreakpointResolutionService with
member this.ResolveBreakpointAsync(document: Document, textSpan: TextSpan, cancellationToken: CancellationToken): Task<FSharpBreakpointResolutionResult> =
asyncMaybe {
let! parsingOptions, _options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, cancellationToken)
let! sourceText = document.GetTextAsync(cancellationToken)
let! range = FSharpBreakpointResolutionService.GetBreakpointLocation(checkerProvider.Checker, sourceText, document.Name, textSpan, parsingOptions)
let! span = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, range)
return BreakpointResolutionResult.CreateSpanResult(document, span)
return FSharpBreakpointResolutionResult.CreateSpanResult(document, span)
}
|> Async.map Option.toObj
|> RoslynHelpers.StartAsyncAsTask cancellationToken

// FSROSLYNTODO: enable placing breakpoints by when user supplies fully-qualified function names
member this.ResolveBreakpointsAsync(_, _, _): Task<IEnumerable<BreakpointResolutionResult>> =
Task.FromResult(Enumerable.Empty<BreakpointResolutionResult>())
member this.ResolveBreakpointsAsync(_, _, _): Task<IEnumerable<FSharpBreakpointResolutionResult>> =
Task.FromResult(Enumerable.Empty<FSharpBreakpointResolutionResult>())
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ open Microsoft.CodeAnalysis.Classification
open Microsoft.CodeAnalysis.Editor.Implementation.Debugging
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor.Implementation.Debugging

open FSharp.Compiler

[<Shared>]
[<ExportLanguageService(typeof<ILanguageDebugInfoService>, FSharpConstants.FSharpLanguageName)>]
[<Export(typeof<IFSharpLanguageDebugInfoService>)>]
type internal FSharpLanguageDebugInfoService [<ImportingConstructor>](projectInfoManager: FSharpProjectOptionsManager) =

static member GetDataTipInformation(sourceText: SourceText, position: int, tokens: List<ClassifiedSpan>): TextSpan option =
Expand All @@ -44,13 +44,13 @@ type internal FSharpLanguageDebugInfoService [<ImportingConstructor>](projectInf

| _ -> None

interface ILanguageDebugInfoService with
interface IFSharpLanguageDebugInfoService with

// FSROSLYNTODO: This is used to get function names in breakpoint window. It should return fully qualified function name and line offset from the start of the function.
member this.GetLocationInfoAsync(_, _, _): Task<DebugLocationInfo> =
Task.FromResult(Unchecked.defaultof<DebugLocationInfo>)
member this.GetLocationInfoAsync(_, _, _): Task<FSharpDebugLocationInfo> =
Task.FromResult(Unchecked.defaultof<FSharpDebugLocationInfo>)

member this.GetDataTipInfoAsync(document: Document, position: int, cancellationToken: CancellationToken): Task<DebugDataTipInfo> =
member this.GetDataTipInfoAsync(document: Document, position: int, cancellationToken: CancellationToken): Task<FSharpDebugDataTipInfo> =
async {
let defines = projectInfoManager.GetCompilationDefinesForEditingDocument(document)
let! cancellationToken = Async.CancellationToken
Expand All @@ -59,8 +59,8 @@ type internal FSharpLanguageDebugInfoService [<ImportingConstructor>](projectInf
let classifiedSpans = Tokenizer.getClassifiedSpans(document.Id, sourceText, textSpan, Some(document.Name), defines, cancellationToken)
let result =
match FSharpLanguageDebugInfoService.GetDataTipInformation(sourceText, position, classifiedSpans) with
| None -> DebugDataTipInfo()
| Some textSpan -> DebugDataTipInfo(textSpan, sourceText.GetSubText(textSpan).ToString())
| None -> FSharpDebugDataTipInfo()
| Some textSpan -> FSharpDebugDataTipInfo(textSpan, sourceText.GetSubText(textSpan).ToString())
return result
}
|> RoslynHelpers.StartAsyncAsTask(cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open System.Threading.Tasks
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Diagnostics
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics

open FSharp.Compiler
open FSharp.Compiler.SourceCodeServices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open FSharp.Compiler
open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices
open System.Runtime.Caching
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics

type private TextVersionHash = int
type private PerDocumentSavedData = { Hash: int; Diagnostics: ImmutableArray<Diagnostic> }
Expand All @@ -39,7 +40,7 @@ type internal SimplifyNameDiagnosticAnalyzer() =
category = DiagnosticCategory.Style,
defaultSeverity = DiagnosticSeverity.Hidden,
isEnabledByDefault = true,
customTags = DiagnosticCustomTags.Unnecessary)
customTags = FSharpDiagnosticCustomTags.Unnecessary)

static member LongIdentPropertyKey = "FullName"
override __.Priority = 100 // Default = 50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open System.Threading.Tasks
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Diagnostics
open FSharp.Compiler.SourceCodeServices
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics

[<DiagnosticAnalyzer(FSharpConstants.FSharpLanguageName)>]
type internal UnusedDeclarationsAnalyzer() =
Expand All @@ -29,7 +30,7 @@ type internal UnusedDeclarationsAnalyzer() =
category = DiagnosticCategory.Style,
defaultSeverity = DiagnosticSeverity.Hidden,
isEnabledByDefault = true,
customTags = DiagnosticCustomTags.Unnecessary)
customTags = FSharpDiagnosticCustomTags.Unnecessary)

let isPotentiallyUnusedDeclaration (symbol: FSharpSymbol) : bool =
match symbol with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ open FSharp.Compiler.Ast
open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices
open Microsoft.VisualStudio.FSharp.Editor.Symbols
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics

[<DiagnosticAnalyzer(FSharpConstants.FSharpLanguageName)>]
type internal UnusedOpensDiagnosticAnalyzer() =
Expand All @@ -33,7 +34,7 @@ type internal UnusedOpensDiagnosticAnalyzer() =
category = DiagnosticCategory.Style,
defaultSeverity = DiagnosticSeverity.Hidden,
isEnabledByDefault = true,
customTags = DiagnosticCustomTags.Unnecessary)
customTags = FSharpDiagnosticCustomTags.Unnecessary)

override __.Priority = 90 // Default = 50
override __.SupportedDiagnostics = ImmutableArray.Create Descriptor
Expand Down
1 change: 1 addition & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="$(MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="Microsoft.CodeAnalysis.EditorFeatures.Wpf" Version="$(MicrosoftCodeAnalysisEditorFeaturesWpfPackageVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisWorkspacesCommonPackageVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="Microsoft.CodeAnalysis.ExternalAccess.FSharp" Version="$(MicrosoftCodeAnalysisWorkspacesCommonPackageVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="Microsoft.Composition" Version="$(MicrosoftCompositionPackageVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="Microsoft.VisualStudio.ComponentModelHost" Version="$(MicrosoftVisualStudioComponentModelHostPackageVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
<PackageReference Include="Microsoft.VisualStudio.Editor" Version="$(MicrosoftVisualStudioEditorPackageVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.Editor
open FSharp.Compiler.SourceCodeServices
open System.Runtime.InteropServices
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor

[<ExportBraceMatcher(FSharpConstants.FSharpLanguageName)>]
[<Export(typeof<IFSharpBraceMatcher>)>]
type internal FSharpBraceMatchingService
[<ImportingConstructor>]
(
Expand All @@ -33,15 +34,15 @@ type internal FSharpBraceMatchingService
return matchedBraces |> Array.tryFind(fun (left, right) -> isPositionInRange left || isPositionInRange right)
}

interface IBraceMatcher with
interface IFSharpBraceMatcher with
member this.FindBracesAsync(document, position, cancellationToken) =
asyncMaybe {
let! parsingOptions, _options = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, cancellationToken)
let! sourceText = document.GetTextAsync(cancellationToken)
let! (left, right) = FSharpBraceMatchingService.GetBraceMatchingResult(checkerProvider.Checker, sourceText, document.Name, parsingOptions, position, defaultUserOpName)
let! leftSpan = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, left)
let! rightSpan = RoslynHelpers.TryFSharpRangeToTextSpan(sourceText, right)
return BraceMatchingResult(leftSpan, rightSpan)
return FSharpBraceMatchingResult(leftSpan, rightSpan)
}
|> Async.map Option.toNullable
|> RoslynHelpers.StartAsyncAsTask cancellationToken
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ open Microsoft.CodeAnalysis.Editor
open Microsoft.CodeAnalysis.Formatting
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor

open FSharp.Compiler.SourceCodeServices
open System.Threading
open System.Windows.Forms

[<Shared>]
[<ExportLanguageService(typeof<IEditorFormattingService>, FSharpConstants.FSharpLanguageName)>]
[<Export(typeof<IFSharpEditorFormattingService>)>]
type internal FSharpEditorFormattingService
[<ImportingConstructor>]
(
Expand Down Expand Up @@ -170,7 +170,7 @@ type internal FSharpEditorFormattingService
return toIList Seq.empty
}

interface IEditorFormattingService with
interface IFSharpEditorFormattingService with
member val SupportsFormatDocument = false
member val SupportsFormatSelection = false
member val SupportsFormatOnPaste = true
Expand Down

0 comments on commit a5510fb

Please sign in to comment.