Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 2a991b6
Author: Don Syme <dsyme@users.noreply.github.com>
Date:   Mon Oct 17 20:40:15 2016 +0100

    Fix microbuild (dotnet#1629)

commit 169d366
Author: Kevin Ransom (msft) <codecutter.fsharp@hotmail.com>
Date:   Sun Oct 16 15:04:50 2016 -0700

    Add missed file. (dotnet#1625)

    * Ensure that portable libraries have correct hintpath for preview 5

    * Replaced missed file

commit d64ff35
Author: Don Syme <dsyme@users.noreply.github.com>
Date:   Sun Oct 16 22:37:08 2016 +0100

    cleanup build and test scripts (dotnet#1615)

    * cleanup build and test scripts

commit 39480c4
Author: Kevin Ransom (msft) <codecutter.fsharp@hotmail.com>
Date:   Sun Oct 16 10:19:03 2016 -0700

    Ensure that portable libraries have correct hintpath for preview 5 (dotnet#1624)

commit 2fe5a3b
Author: Kevin Ransom (msft) <codecutter@hotmail.com>
Date:   Sat Oct 15 14:03:48 2016 -0700

    Add support for generating sourcelink record in portable pdbs.  Fixes dotnet#1585

commit e0318a8
Author: Kevin Ransom (msft) <codecutter.fsharp@hotmail.com>
Date:   Sat Oct 15 13:32:44 2016 -0700

    FSharp ms build task to support new xommand line options (dotnet#1616)

commit 749ba2d
Author: Omar Tawfik <OmarTawfik@users.noreply.github.com>
Date:   Sat Oct 15 13:27:14 2016 -0700

    Don't match braces at the end of the caret (dotnet#1619)

commit 00bab99
Author: Kevin Ransom (msft) <codecutter.fsharp@hotmail.com>
Date:   Sat Oct 15 13:25:15 2016 -0700

    (Nugetize F# templates.  Ensure value tuple installed on create template. (dotnet#1620)

commit 2a9b5ef
Author: Omar Tawfik <OmarTawfik@users.noreply.github.com>
Date:   Fri Oct 14 22:45:35 2016 -0700

    Add fsx files to workspaces (dotnet#1612)

    * Add fsx files to workspaces

    * Stop passing project output paths to CPS

    * Read script file contents from memory (on workspace initialization)

commit 8b434e0
Author: Kevin Ransom (msft) <codecutter.fsharp@hotmail.com>
Date:   Fri Oct 14 10:32:59 2016 -0700

    Don't try to deploy vsix during OSS build.  Specify prereq in vsixmanifest (dotnet#1613)

commit 79430d2
Author: Don Syme <dsyme@users.noreply.github.com>
Date:   Fri Oct 14 15:58:08 2016 +0100

    simplify use of if-defs (dotnet#1614)

commit b708921
Author: Don Syme <dsyme@users.noreply.github.com>
Date:   Fri Oct 14 10:25:28 2016 +0100

    Always use FSharp.Core not fsharp.core (dotnet#1610)
  • Loading branch information
dsyme committed Oct 17, 2016
1 parent 071dbc8 commit c9c4fe6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 35 deletions.
2 changes: 1 addition & 1 deletion BraceMatchingService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type internal FSharpBraceMatchingService() =
static member GetBraceMatchingResult(sourceText, fileName, options, position) = async {
let isPositionInRange(range) =
let span = CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, range)
span.Start <= position && position <= span.End
span.Start <= position && position < span.End
let! matchedBraces = FSharpChecker.Instance.MatchBracesAlternate(fileName, sourceText.ToString(), options)

return matchedBraces |> Seq.tryFind(fun(left, right) -> isPositionInRange(left) || isPositionInRange(right))
Expand Down
1 change: 1 addition & 0 deletions FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
</ItemGroup>
<Import Project="$(FSharpSourcesRoot)\FSharpSource.targets" />
<Import Project="$(VsSdkTargetsDir)\Microsoft.VsSDK.targets" />
<Import Project="$(FSharpSourcesRoot)\..\vsintegration\vsintegration.targets" />
<Target Name="GatherBinariesToBeSigned" AfterTargets="Localize">
<ItemGroup>
<BinariesToBeSigned Include="$(OutDir)$(AssemblyName).dll" />
Expand Down
96 changes: 62 additions & 34 deletions LanguageService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ open System.Runtime.InteropServices
open System.Linq
open System.IO

open Microsoft.FSharp.Compiler.CompileOps
open Microsoft.FSharp.Compiler.SourceCodeServices

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Editor.Options
open Microsoft.VisualStudio
open Microsoft.VisualStudio.Editor
open Microsoft.VisualStudio.TextManager.Interop
open Microsoft.VisualStudio.LanguageServices
open Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
open Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
Expand Down Expand Up @@ -62,47 +65,72 @@ type internal FSharpLanguageService(package : FSharpPackage) =

override this.CreateContext(_,_,_,_,_) = raise(System.NotImplementedException())

override this.SetupNewTextView(view) =
base.SetupNewTextView(view)
let workspace = this.Package.ComponentModel.GetService<VisualStudioWorkspaceImpl>();
override this.SetupNewTextView(textView) =
base.SetupNewTextView(textView)
let workspace = this.Package.ComponentModel.GetService<VisualStudioWorkspaceImpl>()

// FSROSLYNTODO: Hide navigation bars for now. Enable after adding tests
workspace.Options <- workspace.Options.WithChangedOption(NavigationBarOptions.ShowNavigationBar, FSharpCommonConstants.FSharpLanguageName, false)

let (_, buffer) = view.GetBuffer()
let filename = VsTextLines.GetFilename buffer
let result = VsRunningDocumentTable.FindDocumentWithoutLocking(package.RunningDocumentTable,filename)
match result with
| Some (hier, _) ->
match hier with
| :? IProvideProjectSite as siteProvider ->
let site = siteProvider.GetProjectSite()
let projectGuid = Guid(site.ProjectGuid)
let projectFileName = site.ProjectFileName()
let projectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(projectFileName, projectFileName)

let options = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(site, site.ProjectFileName())
if not (optionsCache.ContainsKey(projectId)) then
optionsCache.Add(projectId, options)

if obj.ReferenceEquals(workspace.ProjectTracker.GetProject(projectId), null) then
let projectContextFactory = this.Package.ComponentModel.GetService<IWorkspaceProjectContextFactory>();
let errorReporter = ProjectExternalErrorReporter(projectId, "FS", this.SystemServiceProvider)
let outputFlag = site.CompilerFlags() |> Seq.pick(fun flag ->
if flag.StartsWith("-o:") then Some(flag.Substring(3))
else if flag.StartsWith("--out:") then Some(flag.Substring(6))
else None)
let outputPath = if Path.IsPathRooted(outputFlag) then outputFlag else Path.Combine(Path.GetDirectoryName(projectFileName), outputFlag)

let projectContext = projectContextFactory.CreateProjectContext(FSharpCommonConstants.FSharpLanguageName, projectFileName, projectFileName, projectGuid, hier, outputPath, errorReporter)
let project = projectContext :?> AbstractProject

this.SyncProject(project, projectContext, site)
site.AdviseProjectSiteChanges(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> this.SyncProject(project, projectContext, site)))
site.AdviseProjectSiteClosed(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> project.Disconnect()))
match textView.GetBuffer() with
| (VSConstants.S_OK, textLines) ->
let filename = VsTextLines.GetFilename textLines
match VsRunningDocumentTable.FindDocumentWithoutLocking(package.RunningDocumentTable,filename) with
| Some (hier, _) ->
if IsScript(filename) then
let editorAdapterFactoryService = this.Package.ComponentModel.GetService<IVsEditorAdaptersFactoryService>()
let fileContents = VsTextLines.GetFileContents(textLines, editorAdapterFactoryService)
this.SetupStandAloneFile(filename, fileContents, workspace, hier)
else
match hier with
| :? IProvideProjectSite as siteProvider -> this.SetupProjectFile(siteProvider, workspace)
| _ -> ()
| _ -> ()
| _ -> ()

member this.SetupProjectFile(siteProvider: IProvideProjectSite, workspace: VisualStudioWorkspaceImpl) =
let site = siteProvider.GetProjectSite()
let projectGuid = Guid(site.ProjectGuid)
let projectFileName = site.ProjectFileName()
let projectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(projectFileName, projectFileName)

let options = ProjectSitesAndFiles.GetProjectOptionsForProjectSite(site, site.ProjectFileName())
if not (optionsCache.ContainsKey(projectId)) then
optionsCache.Add(projectId, options)

match workspace.ProjectTracker.GetProject(projectId) with
| null ->
let projectContextFactory = this.Package.ComponentModel.GetService<IWorkspaceProjectContextFactory>();
let errorReporter = ProjectExternalErrorReporter(projectId, "FS", this.SystemServiceProvider)

let projectContext = projectContextFactory.CreateProjectContext(FSharpCommonConstants.FSharpLanguageName, projectFileName, projectFileName, projectGuid, siteProvider, null, errorReporter)
let project = projectContext :?> AbstractProject

this.SyncProject(project, projectContext, site)
site.AdviseProjectSiteChanges(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> this.SyncProject(project, projectContext, site)))
site.AdviseProjectSiteClosed(FSharpCommonConstants.FSharpLanguageServiceCallbackName, AdviseProjectSiteChanges(fun () -> project.Disconnect()))
| _ -> ()

member this.SetupStandAloneFile(fileName: string, fileContents: string, workspace: VisualStudioWorkspaceImpl, hier: IVsHierarchy) =
let options = FSharpChecker.Instance.GetProjectOptionsFromScript(fileName, fileContents, DateTime.Now, [| |]) |> Async.RunSynchronously
let projectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(options.ProjectFileName, options.ProjectFileName)

if not(optionsCache.ContainsKey(projectId)) then
optionsCache.Add(projectId, options)

if obj.ReferenceEquals(workspace.ProjectTracker.GetProject(projectId), null) then
let projectContextFactory = this.Package.ComponentModel.GetService<IWorkspaceProjectContextFactory>();
let errorReporter = ProjectExternalErrorReporter(projectId, "FS", this.SystemServiceProvider)

let projectContext = projectContextFactory.CreateProjectContext(FSharpCommonConstants.FSharpLanguageName, options.ProjectFileName, options.ProjectFileName, projectId.Id, hier, null, errorReporter)
projectContext.AddSourceFile(fileName)

let project = projectContext :?> AbstractProject
let document = project.GetCurrentDocumentFromPath(fileName)

document.Closing.Add(fun _ -> project.Disconnect())


and [<Guid(FSharpCommonConstants.packageGuidString)>]
[<ProvideEditorExtension(FSharpCommonConstants.editorFactoryGuidString, ".fs", 97)>]
[<ProvideEditorExtension(FSharpCommonConstants.editorFactoryGuidString, ".fsi", 97)>]
Expand Down

0 comments on commit c9c4fe6

Please sign in to comment.