Skip to content

Commit c6cebf8

Browse files
author
Omar Tawfik
committed
Addressing code review comments
1 parent b3724db commit c6cebf8

File tree

8 files changed

+36
-52
lines changed

8 files changed

+36
-52
lines changed

vsintegration/src/FSharp.Editor/BraceCompletion.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type internal CompletionContext(tokenContext : TokenContext, textManager : IVsTe
2424
/// Called when user hits Return while inside of a brace completion session.
2525
member this.OnReturn(session) =
2626

27-
let lp = [| LANGPREFERENCES(guidLang = Guid(FSharpCommonConstants.languageServiceGuid)) |]
27+
let lp = [| LANGPREFERENCES(guidLang = Guid(FSharpCommonConstants.languageServiceGuidString)) |]
2828
ErrorHandler.ThrowOnFailure(textManager.GetUserPreferences(null, null, lp, null)) |> ignore
2929

3030
// if smart indent is not enabled, or we are in a string, don't do any special formatting

vsintegration/src/FSharp.Editor/FSharpProjectSiteService.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open Microsoft.CodeAnalysis.Host.Mef
1111
open Microsoft.VisualStudio.FSharp.LanguageService
1212
open Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
1313

14-
// Currently the CompilationOptions type in Roslyn in sealed and there's no way to set the compilation options for a project.
14+
// Currently the CompilationOptions type in Roslyn is sealed and there's no way to set the compilation options for a project.
1515
// There's no property bag on a project either. So this service is a means to get the host project for a given Roslyn project
1616
// so that extra F# specific information can be stored on the host project.
1717
// Note that the FSharpProject is available only through the VS Workspace although we might call this service from projects of

vsintegration/src/FSharp.Editor/SmartIndent.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type SmartIndent (textView : ITextView, textManager : IVsTextManager) =
4949
/// or null when no indentation is desired or unable to determine indentation
5050
member this.GetDesiredIndentation(line : ITextSnapshotLine) =
5151

52-
let lp = [| LANGPREFERENCES(guidLang = Guid(FSharpCommonConstants.languageServiceGuid)) |]
52+
let lp = [| LANGPREFERENCES(guidLang = Guid(FSharpCommonConstants.languageServiceGuidString)) |]
5353
let indentStyle = if ErrorHandler.Succeeded(textManager.GetUserPreferences(null, null, lp, null)) then lp.[0].IndentStyle else vsIndentStyle.vsIndentStyleDefault
5454

5555
if (indentStyle = vsIndentStyle.vsIndentStyleNone || _textView = null || _textView.IsClosed) then

vsintegration/src/FSharp.Editor/extension.vsixmanifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
2+
<!-- Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
33
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
44
<Metadata>
55
<Identity Id="FSharp.Editor" Version="1.0" Language="en-US" Publisher="srivatsn"/>
@@ -14,7 +14,7 @@
1414
<SystemComponent>true</SystemComponent>
1515
</Installation>
1616
<Dependencies>
17-
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
17+
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.6,)" />
1818
</Dependencies>
1919
<Assets>
2020
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="FSharp.Editor.dll"/>

vsintegration/src/FSharp.LanguageService/FSharpCommonConstants.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ open System.Diagnostics
88

99
module internal FSharpCommonConstants =
1010
[<Literal>]
11-
let packageGuid = "871D2A70-12A2-4e42-9440-425DD92A4116"
11+
let packageGuidString = "871D2A70-12A2-4e42-9440-425DD92A4116"
1212
[<Literal>]
13-
let languageServiceGuid = "BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B"
13+
let languageServiceGuidString = "BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B"
1414
[<Literal>]
15-
let editorFactoryGuid = "4EB7CCB7-4336-4FFD-B12B-396E9FD079A9"
15+
let editorFactoryGuidString = "4EB7CCB7-4336-4FFD-B12B-396E9FD079A9"
1616
[<Literal>]
17-
let codePageEditorFactoryGuid = "82A16493-EF43-47E0-B42D-D87BAAB5335D"
17+
let codePageEditorFactoryGuidString = "82A16493-EF43-47E0-B42D-D87BAAB5335D"
1818
[<Literal>]
19-
let svsSettingsPersistenceManagerGuid = "9B164E40-C3A2-4363-9BC5-EB4039DEF653"
19+
let svsSettingsPersistenceManagerGuidString = "9B164E40-C3A2-4363-9BC5-EB4039DEF653"
2020
[<Literal>]
2121
let FSharpLanguageName = "F#"
2222
[<Literal>]

vsintegration/src/FSharp.LanguageService/FSharpLanguageService.fs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ open System.Runtime.InteropServices
99
open Microsoft.FSharp.Compiler.SourceCodeServices
1010

1111
open Microsoft.CodeAnalysis
12-
open Microsoft.CodeAnalysis.SolutionCrawler
1312
open Microsoft.VisualStudio
1413
open Microsoft.VisualStudio.LanguageServices
1514
open Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
@@ -21,18 +20,18 @@ open Microsoft.VisualStudio.Shell.Interop
2120

2221
// Workaround to access non-public settings persistence type.
2322
// GetService( ) with this will work as long as the GUID matches the real type.
24-
[<Guid(FSharpCommonConstants.svsSettingsPersistenceManagerGuid)>]
23+
[<Guid(FSharpCommonConstants.svsSettingsPersistenceManagerGuidString)>]
2524
type internal SVsSettingsPersistenceManager = class end
2625

27-
[<Guid(FSharpCommonConstants.languageServiceGuid)>]
26+
[<Guid(FSharpCommonConstants.languageServiceGuidString)>]
2827
type internal FSharpLanguageService(package : FSharpPackage) =
2928
inherit AbstractLanguageService<FSharpPackage, FSharpLanguageService, FSharpProjectSite>(package)
3029

3130
override this.ContentTypeName = FSharpCommonConstants.FSharpContentTypeName
3231
override this.LanguageName = FSharpCommonConstants.FSharpLanguageName
3332
override this.RoslynLanguageName = FSharpCommonConstants.FSharpLanguageName
3433

35-
override this.LanguageServiceId = new Guid(FSharpCommonConstants.languageServiceGuid)
34+
override this.LanguageServiceId = new Guid(FSharpCommonConstants.languageServiceGuidString)
3635
override this.DebuggerLanguageId = DebuggerEnvironment.GetLanguageID()
3736

3837
override this.CreateContext(_,_,_,_,_) = raise(System.NotImplementedException())
@@ -51,26 +50,26 @@ type internal FSharpLanguageService(package : FSharpPackage) =
5150
match hier with
5251
| :? IProvideProjectSite as siteProvider ->
5352
let site = siteProvider.GetProjectSite()
54-
55-
let projectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(site.ProjectFileName(), site.ProjectFileName())
53+
let projectFileName = site.ProjectFileName()
54+
let projectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(projectFileName, projectFileName)
5655
if obj.ReferenceEquals(workspace.ProjectTracker.GetProject(projectId), null) then
57-
let projectSite = new FSharpProjectSite(hier, this.SystemServiceProvider, workspace, site.ProjectFileName());
56+
let projectSite = new FSharpProjectSite(hier, this.SystemServiceProvider, workspace, projectFileName);
5857
projectSite.Initialize(hier, site)
5958
| _ -> ()
6059
| _ -> ()
6160

62-
and [<Guid(FSharpCommonConstants.editorFactoryGuid)>]
61+
and [<Guid(FSharpCommonConstants.editorFactoryGuidString)>]
6362
internal FSharpEditorFactory(package : FSharpPackage) =
6463
inherit AbstractEditorFactory(package)
6564

6665
override this.ContentTypeName = FSharpCommonConstants.FSharpContentTypeName
67-
override this.GetFormattedTextChanges(_, _, _, _) = System.Collections.Generic.List<Text.TextChange>() :> System.Collections.Generic.IList<Text.TextChange>
66+
override this.GetFormattedTextChanges(_, _, _, _) = upcast Array.empty
6867

69-
and [<Guid(FSharpCommonConstants.codePageEditorFactoryGuid)>]
68+
and [<Guid(FSharpCommonConstants.codePageEditorFactoryGuidString)>]
7069
internal FSharpCodePageEditorFactory(editorFactory: FSharpEditorFactory) =
7170
inherit AbstractCodePageEditorFactory(editorFactory)
7271

73-
and [<Guid(FSharpCommonConstants.packageGuid)>]
72+
and [<Guid(FSharpCommonConstants.packageGuidString)>]
7473
internal FSharpPackage() =
7574
inherit AbstractPackage<FSharpPackage, FSharpLanguageService, FSharpProjectSite>()
7675

@@ -93,7 +92,7 @@ and [<Guid(FSharpCommonConstants.packageGuid)>]
9392
[|
9493
// editorFactory :> IVsEditorFactory;
9594
// codePageEditorFactory :> IVsEditorFactory;
96-
|] :> IEnumerable<IVsEditorFactory>
95+
|] :> seq<IVsEditorFactory>
9796

9897
override this.RegisterMiscellaneousFilesWorkspaceInformation(_) = ()
9998

vsintegration/src/FSharp.LanguageService/FSharpProjectSite.fs

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,18 @@ type internal FSharpProjectSite(hierarchy: IVsHierarchy, serviceProvider: System
3838
site.AdviseProjectSiteClosed(FSharpCommonConstants.FSharpLanguageServiceCallbackName,
3939
new AdviseProjectSiteChanges(fun () -> this.Disconnect()))
4040

41-
// Add files and references.
42-
site.SourceFilesOnDisk() |>
43-
Seq.iter(fun file -> this.AddDocument(hier, file))
44-
45-
this.GetReferences(site.CompilerFlags()) |>
46-
Seq.iter(fun ref -> this.AddReference(ref) |> ignore)
41+
// Add files and references
42+
for file in site.SourceFilesOnDisk() do this.AddDocument(hier, file)
43+
for ref in this.GetReferences(site.CompilerFlags()) do this.AddReference(ref)
4744

4845
// Capture the F# specific options that we'll pass to the type checker.
4946
checkOptions <- Some(ProjectSitesAndFiles.GetProjectOptionsForProjectSite(site, site.ProjectFileName()))
5047

5148
member this.GetReferences(flags : string[]) =
52-
let (|Reference|_|) (f : string) = if f.StartsWith("-r:") then Some (f.Replace("-r:", "")) else None
53-
54-
let references = flags |>
55-
Seq.map(fun flag -> match flag with
56-
| Reference ref -> ref
57-
| _ -> "") |>
58-
Seq.where(fun s -> s <> "")
59-
references
49+
flags |> Array.choose(fun flag -> if flag.StartsWith("-r:") then Some(flag.Substring(3)) else None)
6050

6151
member this.AddReference(filePath : string) =
62-
this.AddMetadataReferenceAndTryConvertingToProjectReferenceIfPossible(filePath, new MetadataReferenceProperties(), VSConstants.S_FALSE)
52+
this.AddMetadataReferenceAndTryConvertingToProjectReferenceIfPossible(filePath, new MetadataReferenceProperties(), VSConstants.S_FALSE) |> ignore
6353

6454
member this.RemoveReference(filePath: string) =
6555
this.RemoveMetadataReference(filePath)
@@ -75,24 +65,19 @@ type internal FSharpProjectSite(hierarchy: IVsHierarchy, serviceProvider: System
7565

7666
member internal this.OnProjectSettingsChanged(hier: IVsHierarchy, site : IProjectSite) =
7767
let sourceFiles = site.SourceFilesOnDisk()
78-
// Added files.
79-
sourceFiles |>
80-
Seq.where(fun file -> not(this.ContainsFile(file))) |>
81-
Seq.iter(fun file -> this.AddDocument(hier, file))
82-
// Removed files.
83-
this.GetCurrentDocuments() |>
84-
Seq.where(fun doc -> not(sourceFiles |> Seq.contains(doc.FilePath))) |>
85-
Seq.iter(fun doc -> this.RemoveDocument(doc))
8668

69+
// Added files
70+
for file in sourceFiles do if not(this.ContainsFile(file)) then this.AddDocument(hier, file)
71+
// Removed files
72+
let removedDocuments = this.GetCurrentDocuments() |> Seq.where(fun doc -> not(sourceFiles |> Seq.contains(doc.FilePath))) |> Seq.toList
73+
for doc in removedDocuments do this.RemoveDocument(doc)
74+
8775
let references = this.GetReferences(site.CompilerFlags())
76+
8877
// Added references
89-
references |>
90-
Seq.where(fun ref -> not(this.HasMetadataReference(ref))) |>
91-
Seq.iter(fun ref -> this.AddReference(ref) |> ignore)
78+
for ref in references do if not(this.HasMetadataReference(ref)) then this.AddReference(ref)
9279
// Removed references
93-
this.GetCurrentMetadataReferences() |>
94-
Seq.where(fun ref -> not(references |> Seq.contains(ref.FilePath))) |>
95-
Seq.iter(fun ref -> this.RemoveReference(ref.FilePath))
80+
for ref in this.GetCurrentMetadataReferences() do if not(references |> Seq.contains(ref.FilePath)) then this.RemoveReference(ref.FilePath)
9681

9782
// If the order of files changed, that'll be captured in the checkOptions.
9883
checkOptions <- Some(ProjectSitesAndFiles.GetProjectOptionsForProjectSite(site, site.ProjectFileName()))

vsintegration/src/FSharp.ProjectSystem.FSharp/Project.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ See also ...\SetupAuthoring\FSharp\Registry\FSProjSys_Registration.wxs, e.g.
751751

752752
override x.GetGuidProperty(propid:int, guid:byref<Guid> ) =
753753
if (enum propid = __VSHPROPID.VSHPROPID_PreferredLanguageSID) then
754-
guid <- new Guid(FSharpCommonConstants.languageServiceGuid)
754+
guid <- new Guid(FSharpCommonConstants.languageServiceGuidString)
755755
VSConstants.S_OK
756756
// below is how VS decide 'which templates' to associate with an 'add new item' call in this project
757757
elif (enum propid = __VSHPROPID2.VSHPROPID_AddItemTemplatesGuid) then

0 commit comments

Comments
 (0)