Skip to content

Commit e161cf3

Browse files
authored
Merge pull request #1581 from OmarTawfik/roslyn
Update Roslyn to base off beta6 version of Roslyn + Type Colorization
2 parents 08d8c6d + c413c0b commit e161cf3

File tree

16 files changed

+97
-154
lines changed

16 files changed

+97
-154
lines changed

.nuget/NuGet.Config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
99
<clear />
1010
<add key="myget.org fsharp-daily" value="https://www.myget.org/F/fsharp-daily/api/v3/index.json" />
11-
<add key="myget.org roslyn-dev15-preview4-df-nightly" value="https://dotnet.myget.org/F/roslyn-dev15-preview4-df-nightly/api/v3/index.json" />
11+
<add key="myget.org roslyn-master-nightly" value="https://dotnet.myget.org/F/roslyn-master-nightly/api/v3/index.json" />
1212
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
1313
<add key="myget.org dotnet-buildtools" value="https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json" />
1414
<add key="myget.org roslyn-tools" value="https://dotnet.myget.org/F/roslyn-tools/api/v3/index.json" />

packages.config

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
<package id="WiX.Toolset.2015" version="3.10.0.1503" />
1919
<package id="Microsoft.VisualFSharp.Core.Redist" version="1.0.0" />
2020
<package id="Microsoft.VisualFSharp.Type.Providers.Redist" version="1.0.0" />
21-
<package id="Microsoft.CodeAnalysis.Common" version="2.0.0-beta4-60808-03" targetFramework="net46" />
22-
<package id="Microsoft.CodeAnalysis.EditorFeatures" version="2.0.0-beta4-60808-03" targetFramework="net46" />
23-
<package id="Microsoft.CodeAnalysis.EditorFeatures.Text" version="2.0.0-beta4-60808-03" targetFramework="net46" />
24-
<package id="Microsoft.CodeAnalysis.Features" version="2.0.0-beta4-60808-03" targetFramework="net46" />
25-
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="2.0.0-beta4-60808-03" targetFramework="net46" />
26-
<package id="Microsoft.VisualStudio.LanguageServices" version="2.0.0-beta4-60808-03" targetFramework="net46" />
21+
<package id="Microsoft.CodeAnalysis.Common" version="2.0.0-beta6-61005-05" targetFramework="net46" />
22+
<package id="Microsoft.CodeAnalysis.EditorFeatures" version="2.0.0-beta6-61005-05" targetFramework="net46" />
23+
<package id="Microsoft.CodeAnalysis.EditorFeatures.Text" version="2.0.0-beta6-61005-05" targetFramework="net46" />
24+
<package id="Microsoft.CodeAnalysis.Features" version="2.0.0-beta6-61005-05" targetFramework="net46" />
25+
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="2.0.0-beta6-61005-05" targetFramework="net46" />
26+
<package id="Microsoft.VisualStudio.LanguageServices" version="2.0.0-beta6-61005-05" targetFramework="net46" />
2727
<package id="Microsoft.Composition" version="1.0.27" targetFramework="net46" />
2828
<package id="Microsoft.VisualStudio.Threading" version="14.1.131" targetFramework="net46" />
2929
<package id="Microsoft.VisualStudio.Shell.14.0" version="14.3.25407" targetFramework="net46" />

src/FSharpSource.Settings.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<FsiToolExe>fsi.exe</FsiToolExe>
9191
<FsLexToolExe>fslex.exe</FsLexToolExe>
9292
<FsYaccToolExe>fsyacc.exe</FsYaccToolExe>
93-
<RoslynVersion>2.0.0-beta4-60808-03</RoslynVersion>
93+
<RoslynVersion>2.0.0-beta6-61005-05</RoslynVersion>
9494
<RoslynVSBinariesVersion>14.0</RoslynVSBinariesVersion>
9595
<RoslynVSPackagesVersion>14.3.25407</RoslynVSPackagesVersion>
9696
</PropertyGroup>

vsintegration/src/FSharp.Editor/ColorizationService.fs

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ type private SourceTextData(lines: int) =
3737
type internal FSharpColorizationService() =
3838

3939
static let DataCache = ConditionalWeakTable<SourceText, SourceTextData>()
40+
41+
static let compilerTokenToRoslynToken(colorKind: FSharpTokenColorKind) : string =
42+
match colorKind with
43+
| FSharpTokenColorKind.Comment -> ClassificationTypeNames.Comment
44+
| FSharpTokenColorKind.Identifier -> ClassificationTypeNames.Identifier
45+
| FSharpTokenColorKind.Keyword -> ClassificationTypeNames.Keyword
46+
| FSharpTokenColorKind.String -> ClassificationTypeNames.StringLiteral
47+
| FSharpTokenColorKind.Text -> ClassificationTypeNames.Text
48+
| FSharpTokenColorKind.UpperIdentifier -> ClassificationTypeNames.Identifier
49+
| FSharpTokenColorKind.Number -> ClassificationTypeNames.NumericLiteral
50+
| FSharpTokenColorKind.InactiveCode -> ClassificationTypeNames.ExcludedCode
51+
| FSharpTokenColorKind.PreprocessorKeyword -> ClassificationTypeNames.PreprocessorKeyword
52+
| FSharpTokenColorKind.Operator -> ClassificationTypeNames.Operator
53+
| FSharpTokenColorKind.TypeName -> ClassificationTypeNames.ClassName
54+
| FSharpTokenColorKind.Default | _ -> ClassificationTypeNames.Text
4055

4156
static let scanSourceLine(sourceTokenizer: FSharpSourceTokenizer, textLine: TextLine, lineContents: string, lexState: FSharpTokenizerLexState) : SourceLineData =
4257

4358
let colorMap = Array.create textLine.Span.Length ClassificationTypeNames.Text
4459
let lineTokenizer = sourceTokenizer.CreateLineTokenizer(lineContents)
45-
46-
let compilerTokenToRoslynToken(colorKind: FSharpTokenColorKind) : string =
47-
match colorKind with
48-
| FSharpTokenColorKind.Comment -> ClassificationTypeNames.Comment
49-
| FSharpTokenColorKind.Identifier -> ClassificationTypeNames.Identifier
50-
| FSharpTokenColorKind.Keyword -> ClassificationTypeNames.Keyword
51-
| FSharpTokenColorKind.String -> ClassificationTypeNames.StringLiteral
52-
| FSharpTokenColorKind.Text -> ClassificationTypeNames.Text
53-
| FSharpTokenColorKind.UpperIdentifier -> ClassificationTypeNames.Identifier
54-
| FSharpTokenColorKind.Number -> ClassificationTypeNames.NumericLiteral
55-
| FSharpTokenColorKind.InactiveCode -> ClassificationTypeNames.ExcludedCode
56-
| FSharpTokenColorKind.PreprocessorKeyword -> ClassificationTypeNames.PreprocessorKeyword
57-
| FSharpTokenColorKind.Operator -> ClassificationTypeNames.Operator
58-
| FSharpTokenColorKind.TypeName -> ClassificationTypeNames.ClassName
59-
| FSharpTokenColorKind.Default | _ -> ClassificationTypeNames.Text
6060

6161
let scanAndColorNextToken(lineTokenizer: FSharpLineTokenizer, lexState: Ref<FSharpTokenizerLexState>) : Option<FSharpTokenInfo> =
6262
let tokenInfoOption, nextLexState = lineTokenizer.ScanToken(lexState.Value)
@@ -144,17 +144,14 @@ type internal FSharpColorizationService() =
144144
| None -> ()
145145
, cancellationToken)
146146

147-
// FSROSLYNTODO: Due to issue 12732 on Roslyn side, semantic classification is tied to C#/VB only.
148-
// Once that is exposed to F#, enable the below code path, and add tests accourdingly.
149-
member this.AddSemanticClassificationsAsync(_, _, _, _) =
150-
(*
147+
member this.AddSemanticClassificationsAsync(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken) =
151148
let computation = async {
152-
try
153-
let options = CommonRoslynHelpers.GetFSharpProjectOptionsForRoslynProject(document.Project)
149+
match FSharpLanguageService.GetOptions(document.Project.Id) with
150+
| Some(options) ->
154151
let! sourceText = document.GetTextAsync(cancellationToken) |> Async.AwaitTask
155152
let! parseResults = FSharpChecker.Instance.ParseFileInProject(document.Name, sourceText.ToString(), options)
156153
let! textVersion = document.GetTextVersionAsync(cancellationToken) |> Async.AwaitTask
157-
let! checkResultsAnswer = FSharpChecker.Instance.CheckFileInProject(parseResults, document.Name, textVersion.GetHashCode(), textSpan.ToString(), options)
154+
let! checkResultsAnswer = FSharpChecker.Instance.CheckFileInProject(parseResults, document.FilePath, textVersion.GetHashCode(), textSpan.ToString(), options)
158155

159156
let extraColorizationData = match checkResultsAnswer with
160157
| FSharpCheckFileAnswer.Aborted -> failwith "Compilation isn't complete yet"
@@ -163,13 +160,10 @@ type internal FSharpColorizationService() =
163160
|> Seq.toList
164161

165162
result.AddRange(extraColorizationData)
166-
with ex ->
167-
Assert.Exception(ex)
168-
raise(ex)
163+
| None -> ()
169164
}
170-
Task.Run(fun () -> Async.RunSynchronously(computation, cancellationToken = cancellationToken))
171-
*)
172-
Task.CompletedTask
173-
165+
166+
Task.Run(CommonRoslynHelpers.GetTaskAction(computation), cancellationToken)
167+
174168
// Do not perform classification if we don't have project options (#defines matter)
175169
member this.AdjustStaleClassification(_: SourceText, classifiedSpan: ClassifiedSpan) : ClassifiedSpan = classifiedSpan

vsintegration/src/FSharp.Editor/DocumentDiagnosticAnalyzer.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
3131
let severity = if error.Severity = FSharpErrorSeverity.Error then DiagnosticSeverity.Error else DiagnosticSeverity.Warning
3232
let descriptor = new DiagnosticDescriptor(id, emptyString, description, error.Subcategory, severity, true, emptyString, String.Empty, null)
3333

34-
let linePositionSpan = LinePositionSpan(LinePosition(error.StartLineAlternate - 1, error.StartColumn), LinePosition(error.EndLineAlternate - 1, error.EndColumn))
34+
// F# compiler report errors at start/end of file if parsing fails. It should be corrected to match Roslyn boundaries
35+
let linePositionSpan = LinePositionSpan(
36+
LinePosition(Math.Max(0, error.StartLineAlternate - 1), error.StartColumn),
37+
LinePosition(Math.Max(0, error.EndLineAlternate - 1), error.EndColumn))
3538
let textSpan = sourceText.Lines.GetTextSpan(linePositionSpan)
36-
37-
// F# compiler report errors at end of file if parsing fails. It should be corrected to match Roslyn boundaries
3839
let correctedTextSpan = if textSpan.End < sourceText.Length then textSpan else TextSpan.FromBounds(sourceText.Length - 1, sourceText.Length)
3940

4041
Diagnostic.Create(descriptor, Location.Create(filePath, correctedTextSpan , linePositionSpan))

vsintegration/src/FSharp.Editor/DocumentDifferenceService.fs

Lines changed: 0 additions & 28 deletions
This file was deleted.

vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<Compile Include="AssemblyInfo.fs" />
3333
<Compile Include="CommonConstants.fs" />
3434
<Compile Include="CommonRoslynHelpers.fs" />
35-
<Compile Include="ProjectSite.fs" />
3635
<Compile Include="LanguageService.fs" />
3736
<Compile Include="ColorizationService.fs">
3837
<Link>Classification\ColorizationService.fs</Link>
@@ -49,9 +48,6 @@
4948
<Compile Include="LanguageDebugInfoService.fs">
5049
<Link>Debugging\LanguageDebugInfoService.fs</Link>
5150
</Compile>
52-
<Compile Include="DocumentDifferenceService.fs">
53-
<Link>Diagnostics\DocumentDifferenceService.fs</Link>
54-
</Compile>
5551
<Compile Include="DocumentDiagnosticAnalyzer.fs">
5652
<Link>Diagnostics\DocumentDiagnosticAnalyzer.fs</Link>
5753
</Compile>

vsintegration/src/FSharp.Editor/GoToDefinitionService.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ open Microsoft.CodeAnalysis
1616
open Microsoft.CodeAnalysis.Classification
1717
open Microsoft.CodeAnalysis.Editor
1818
open Microsoft.CodeAnalysis.Editor.Host
19-
open Microsoft.CodeAnalysis.Editor.Navigation
19+
open Microsoft.CodeAnalysis.Navigation
2020
open Microsoft.CodeAnalysis.Editor.Shared.Utilities
2121
open Microsoft.CodeAnalysis.Host.Mef
2222
open Microsoft.CodeAnalysis.Text
@@ -29,12 +29,15 @@ open Microsoft.FSharp.Compiler.Range
2929
open Microsoft.FSharp.Compiler.SourceCodeServices
3030

3131
type internal FSharpNavigableItem(document: Document, textSpan: TextSpan, displayString: string) =
32+
member this.DisplayString = displayString
33+
3234
interface INavigableItem with
3335
member this.Glyph = Glyph.BasicFile
3436
member this.DisplayFileLocation = true
35-
member this.DisplayString = displayString
37+
member this.IsImplicitlyDeclared = false
3638
member this.Document = document
3739
member this.SourceSpan = textSpan
40+
member this.DisplayTaggedParts = Unchecked.defaultof<ImmutableArray<TaggedText>>
3841
member this.ChildItems = ImmutableArray<INavigableItem>.Empty
3942

4043
[<Shared>]
@@ -124,7 +127,7 @@ type internal FSharpGoToDefinitionService [<ImportingConstructor>] ([<ImportMany
124127

125128
if definitionTask.Status = TaskStatus.RanToCompletion then
126129
if definitionTask.Result.Any() then
127-
let navigableItem = definitionTask.Result.First() // F# API provides only one INavigableItem
130+
let navigableItem = definitionTask.Result.First() :?> FSharpNavigableItem // F# API provides only one INavigableItem
128131
for presenter in presenters do
129132
presenter.DisplayResult(navigableItem.DisplayString, definitionTask.Result)
130133
true

vsintegration/src/FSharp.Editor/IndentationService.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ type internal FSharpIndentationService() =
4848

4949
interface ISynchronousIndentationService with
5050
member this.GetDesiredIndentation(document: Document, lineNumber: int, cancellationToken: CancellationToken): Nullable<IndentationResult> =
51-
let sourceTextTask= document.GetTextAsync(cancellationToken)
51+
let sourceTextTask = document.GetTextAsync(cancellationToken)
5252
sourceTextTask.Wait(cancellationToken)
53-
5453
let sourceText = CommonRoslynHelpers.GetCompletedTaskResult(sourceTextTask)
55-
let tabSize = document.Options.GetOption(FormattingOptions.TabSize, FSharpCommonConstants.FSharpLanguageName)
54+
55+
let optionsTask = document.GetOptionsAsync(cancellationToken)
56+
optionsTask.Wait(cancellationToken)
57+
let options = CommonRoslynHelpers.GetCompletedTaskResult(optionsTask)
58+
let tabSize = options.GetOption(FormattingOptions.TabSize, FSharpCommonConstants.FSharpLanguageName)
5659

5760
match FSharpIndentationService.GetDesiredIndentation(sourceText, lineNumber, tabSize) with
5861
| None -> Nullable<IndentationResult>()

vsintegration/src/FSharp.Editor/LanguageService.fs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace Microsoft.VisualStudio.FSharp.Editor
55
open System
66
open System.Collections.Generic
77
open System.Runtime.InteropServices
8+
open System.Linq
9+
open System.IO
810

911
open Microsoft.FSharp.Compiler.SourceCodeServices
1012

@@ -15,7 +17,9 @@ open Microsoft.VisualStudio.LanguageServices
1517
open Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
1618
open Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
1719
open Microsoft.VisualStudio.LanguageServices.Implementation.DebuggerIntelliSense
20+
open Microsoft.VisualStudio.LanguageServices.Implementation.TaskList
1821
open Microsoft.VisualStudio.LanguageServices.Implementation
22+
open Microsoft.VisualStudio.LanguageServices.ProjectSystem
1923
open Microsoft.VisualStudio.Shell
2024
open Microsoft.VisualStudio.Shell.Interop
2125
open Microsoft.VisualStudio.FSharp.LanguageService
@@ -27,7 +31,7 @@ type internal SVsSettingsPersistenceManager = class end
2731

2832
[<Guid(FSharpCommonConstants.languageServiceGuidString)>]
2933
type internal FSharpLanguageService(package : FSharpPackage) =
30-
inherit AbstractLanguageService<FSharpPackage, FSharpLanguageService, FSharpProjectSite>(package)
34+
inherit AbstractLanguageService<FSharpPackage, FSharpLanguageService>(package)
3135

3236
static let optionsCache = Dictionary<ProjectId, FSharpProjectOptions>()
3337
static member GetOptions(projectId: ProjectId) =
@@ -36,6 +40,13 @@ type internal FSharpLanguageService(package : FSharpPackage) =
3640
else
3741
None
3842

43+
member this.SyncProject(project: AbstractProject, projectContext: IWorkspaceProjectContext, site: IProjectSite) =
44+
let updatedFiles = site.SourceFilesOnDisk()
45+
let workspaceFiles = project.GetCurrentDocuments() |> Seq.map(fun file -> file.FilePath)
46+
47+
for file in updatedFiles do if not(workspaceFiles.Contains(file)) then projectContext.AddSourceFile(file)
48+
for file in workspaceFiles do if not(updatedFiles.Contains(file)) then projectContext.RemoveSourceFile(file)
49+
3950
override this.ContentTypeName = FSharpCommonConstants.FSharpContentTypeName
4051
override this.LanguageName = FSharpCommonConstants.FSharpLanguageName
4152
override this.RoslynLanguageName = FSharpCommonConstants.FSharpLanguageName
@@ -52,7 +63,6 @@ type internal FSharpLanguageService(package : FSharpPackage) =
5263
// FSROSLYNTODO: Hide navigation bars for now. Enable after adding tests
5364
workspace.Options <- workspace.Options.WithChangedOption(NavigationBarOptions.ShowNavigationBar, FSharpCommonConstants.FSharpLanguageName, false)
5465

55-
// Ensure that we have a project in the workspace for this document.
5666
let (_, buffer) = view.GetBuffer()
5767
let filename = VsTextLines.GetFilename buffer
5868
let result = VsRunningDocumentTable.FindDocumentWithoutLocking(package.RunningDocumentTable,filename)
@@ -61,6 +71,7 @@ type internal FSharpLanguageService(package : FSharpPackage) =
6171
match hier with
6272
| :? IProvideProjectSite as siteProvider ->
6373
let site = siteProvider.GetProjectSite()
74+
let projectGuid = Guid(site.ProjectGuid)
6475
let projectFileName = site.ProjectFileName()
6576
let projectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(projectFileName, projectFileName)
6677

@@ -69,14 +80,26 @@ type internal FSharpLanguageService(package : FSharpPackage) =
6980
optionsCache.Add(projectId, options)
7081

7182
if obj.ReferenceEquals(workspace.ProjectTracker.GetProject(projectId), null) then
72-
let projectSite = new FSharpProjectSite(hier, this.SystemServiceProvider, workspace, projectFileName);
73-
projectSite.Initialize(hier, site)
83+
let projectContextFactory = this.Package.ComponentModel.GetService<IWorkspaceProjectContextFactory>();
84+
let errorReporter = ProjectExternalErrorReporter(projectId, "FS", this.SystemServiceProvider)
85+
let outputFlag = site.CompilerFlags() |> Seq.pick(fun flag ->
86+
if flag.StartsWith("-o:") then Some(flag.Substring(3))
87+
else if flag.StartsWith("--out:") then Some(flag.Substring(6))
88+
else None)
89+
let outputPath = if Path.IsPathRooted(outputFlag) then outputFlag else Path.Combine(Path.GetDirectoryName(projectFileName), outputFlag)
90+
91+
let projectContext = projectContextFactory.CreateProjectContext(FSharpCommonConstants.FSharpLanguageName, projectFileName, projectFileName, projectGuid, hier, outputPath, errorReporter)
92+
let project = projectContext :?> AbstractProject
93+
94+
this.SyncProject(project, projectContext, site)
95+
site.AdviseProjectSiteChanges(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> this.SyncProject(project, projectContext, site)))
96+
site.AdviseProjectSiteClosed(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> project.Disconnect()))
7497
| _ -> ()
7598
| _ -> ()
7699

77100
and [<Guid(FSharpCommonConstants.packageGuidString)>]
78101
internal FSharpPackage() =
79-
inherit AbstractPackage<FSharpPackage, FSharpLanguageService, FSharpProjectSite>()
102+
inherit AbstractPackage<FSharpPackage, FSharpLanguageService>()
80103

81104
override this.RoslynLanguageName = FSharpCommonConstants.FSharpLanguageName
82105

0 commit comments

Comments
 (0)