Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions vsintegration/src/FSharp.Editor/Common/Error.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ type internal Assert() =
/// Display a good exception for this error message and then rethrow.
static member Exception(e:Exception) =
System.Diagnostics.Debug.Assert(false, "Unexpected exception seen in language service", e.ToString())




70 changes: 69 additions & 1 deletion vsintegration/src/FSharp.Editor/Common/Vs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,84 @@
namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.Runtime.InteropServices
open Microsoft.VisualStudio
open Microsoft.VisualStudio.Editor
open Microsoft.VisualStudio.Shell.Interop
open Microsoft.VisualStudio.TextManager.Interop

/// Helper methods for interoperating with COM
module internal Com =
module internal Com =
let ThrowOnFailure0(hr) =
ErrorHandler.ThrowOnFailure(hr) |> ignore

let ThrowOnFailure1(hr,res) =
ErrorHandler.ThrowOnFailure(hr) |> ignore;
res

let ThrowOnFailure2(hr,res1,res2) =
ErrorHandler.ThrowOnFailure(hr) |> ignore;
res1,res2

let ThrowOnFailure3(hr,res1,res2,res3) =
ErrorHandler.ThrowOnFailure(hr) |> ignore;
res1,res2,res3

let ThrowOnFailure4(hr,res1,res2,res3,res4) =
ErrorHandler.ThrowOnFailure(hr) |> ignore;
res1,res2,res3,res4

let Succeeded hr =
// REVIEW: Not the correct check for succeeded
hr = VSConstants.S_OK

module internal VsUserData =

let vsBufferMoniker = Guid("978A8E17-4DF8-432A-9623-D530A26452BC")

// This is the file name of the buffer.
let GetBufferMonker(ud:IVsUserData) : string =
downcast Com.ThrowOnFailure1(ud.GetData(ref vsBufferMoniker))

module internal VsTextLines =
/// Get the length of the given line.
let LengthOfLine (buffer:IVsTextBuffer) (line:int) : int =
Com.ThrowOnFailure1(buffer.GetLengthOfLine(line))

/// Get the text for a particular line.
let LineText (buffer:IVsTextLines) line =
Com.ThrowOnFailure1(buffer.GetLineText(line, 0, line, LengthOfLine buffer line))

/// Get the color state
let TextColorState (buffer:IVsTextLines) : IVsTextColorState= unbox(box(buffer))

/// Get the filename of the given buffer (via IVsUserData). Not all buffers have a file. This will be an exception.
let GetFilename(buffer : IVsTextLines) =
let ud = (box buffer) :?> IVsUserData
VsUserData.GetBufferMonker(ud)

/// Get the string contents of a given buffer (the current snapshot).
let GetFileContents(buffer: IVsTextBuffer, editorAdaptersFactoryService: IVsEditorAdaptersFactoryService) =
let dataBuffer = editorAdaptersFactoryService.GetDataBuffer(buffer)
dataBuffer.CurrentSnapshot.GetText()

module internal VsRunningDocumentTable =
let FindDocumentWithoutLocking(rdt:IVsRunningDocumentTable, url:string) : (IVsHierarchy * IVsTextLines) option =
let (hr:int, hier:IVsHierarchy, _itemid:uint32, unkData:IntPtr, _cookie:uint32) = rdt.FindAndLockDocument(uint32 _VSRDTFLAGS.RDT_NoLock, url)
try
if Com.Succeeded(hr) then
let bufferObject =
if unkData=IntPtr.Zero then null
else Marshal.GetObjectForIUnknown(unkData)
let buffer =
match bufferObject with
| :? IVsTextLines as tl -> tl
| _ -> null
Some(hier, buffer)
else None
finally
if IntPtr.Zero <> unkData then Marshal.Release(unkData)|>ignore

[<AutoOpen>]
module internal ServiceProviderExtensions =
type internal System.IServiceProvider with
Expand Down
19 changes: 7 additions & 12 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
<InternalsVisibleTo Include="FSharp.ProjectSystem.FSharp" />
<InternalsVisibleTo Include="VisualFSharp.UnitTests" />
<InternalsVisibleTo Include="VisualFSharp.Salsa" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FSharp.Editor.resx">
<GenerateSource>true</GenerateSource>
<GeneratedModuleName>Microsoft.VisualStudio.FSharp.Editor.SR</GeneratedModuleName>
Expand All @@ -42,18 +40,20 @@
<Compile Include="Common\Pervasive.fs" />
<Compile Include="Common\Extensions.fs" />
<Compile Include="Common\Constants.fs" />
<Compile Include="Common\Error.fs" />
<Compile Include="Common\Logging.fs" />
<Compile Include="Common\RoslynHelpers.fs" />
<Compile Include="Common\CodeAnalysisExtensions.fs" />
<Compile Include="Common\ContentType.fs" />
<Compile Include="Common\Error.fs" />
<Compile Include="Common\Vs.fs" />
<Compile Include="Options\SettingsPersistence.fs" />
<Compile Include="Options\UIHelpers.fs" />
<Compile Include="Options\EditorOptions.fs" />
<Compile Include="LanguageService\Tokenizer.fs" />
<Compile Include="LanguageService\Symbols.fs" />
<Compile Include="LanguageService\FSharpCheckerExtensions.fs" />
<Compile Include="LanguageService\IProjectSite.fs" />
<Compile Include="LanguageService\ProjectSitesAndFiles.fs" />
<Compile Include="LanguageService\LanguageService.fs" />
<Compile Include="LanguageService\AssemblyContentProvider.fs" />
<Compile Include="LanguageService\SymbolHelpers.fs" />
Expand Down Expand Up @@ -107,11 +107,6 @@
<Project>{DED3BBD7-53F4-428A-8C9F-27968E768605}</Project>
<Name>FSharp.Core</Name>
</ProjectReference>
<ProjectReference Include="$(FSharpSourcesRoot)\..\vsintegration\src\FSharp.LanguageService\FSharp.LanguageService.fsproj">
<Name>FSharp.LanguageService</Name>
<Project>{ee85aab7-cda0-4c4e-bda0-a64ccc413e3f}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="$(FSharpSourcesRoot)\..\vsintegration\src\FSharp.LanguageService.Base\FSharp.LanguageService.Base.csproj">
<Name>FSharp.LanguageService.Base</Name>
<Project>{1c5c163c-37ea-4a3c-8ccc-0d34b74bf8ef}</Project>
Expand All @@ -132,8 +127,6 @@
<Project>{991dcf75-c2eb-42b6-9a0d-aa1d2409d519}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Windows.Forms" />
Expand All @@ -146,8 +139,6 @@
<Reference Include="System" />
<Reference Include="PresentationCore" />
<Reference Include="System.ComponentModel.Composition" />
</ItemGroup>
<ItemGroup>
<Reference Include="EnvDTE">
<HintPath>$(FSharpSourcesRoot)\..\packages\EnvDTE.8.0.1\lib\net10\EnvDTE.dll</HintPath>
<Private>True</Private>
Expand All @@ -156,6 +147,10 @@
<HintPath>$(FSharpSourcesRoot)\..\packages\EnvDTE80.8.0.1\lib\net10\EnvDTE80.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="VSLangProj">
<HintPath>$(FSharpSourcesRoot)\..\packages\VSSDK.VSLangProj.7.0.4\lib\net20\VSLangProj.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.Threading">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualStudio.Threading.$(MicrosoftVisualStudioThreadingVersion)\lib\net45\Microsoft.VisualStudio.Threading.dll</HintPath>
</Reference>
Expand Down
61 changes: 61 additions & 0 deletions vsintegration/src/FSharp.Editor/LanguageService/IProjectSite.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace Microsoft.VisualStudio.FSharp.Editor

open System.Runtime.InteropServices

/// Narrow abstraction over the project system.
type internal AdviseProjectSiteChanges = delegate of unit -> unit

[<ComImport; InterfaceType(ComInterfaceType.InterfaceIsIUnknown); Guid("ad98f020-bad0-0000-0000-abc037459871")>]
type internal IProvideProjectSite =
abstract GetProjectSite : unit -> IProjectSite

/// Represents known F#-specific information about a project.
and internal IProjectSite =

/// List of files in the project. In the correct order.
abstract CompilationSourceFiles : string[]

/// Flags that the compiler would need to understand how to compile. Includes '-r'
/// options but not source files
abstract CompilationOptions : string[]

/// The normalized '-r:' assembly references, without the '-r:'
abstract CompilationReferences : string []

/// The '-o:' output bin path, without the '-o:'
abstract CompilationBinOutputPath : string option

/// The name of the project file.
abstract ProjectFileName : string

/// Register for notifications for when the above change
abstract AdviseProjectSiteChanges : callbackOwnerKey: string * AdviseProjectSiteChanges -> unit

/// Register for notifications when project is cleaned/rebuilt (and thus any live TypeProviders should be refreshed)
abstract AdviseProjectSiteCleaned : callbackOwnerKey: string * AdviseProjectSiteChanges -> unit

// Register for notifications when project is closed.
abstract AdviseProjectSiteClosed : callbackOwnerKey: string * AdviseProjectSiteChanges -> unit

/// A user-friendly description of the project. Used only for developer/DEBUG tooltips and such.
abstract Description : string

/// The error list task reporter
abstract BuildErrorReporter : Microsoft.VisualStudio.Shell.Interop.IVsLanguageServiceBuildErrorReporter2 option with get, set

/// False type resolution errors are invalid. This occurs with orphaned source files. The prior
/// type checking state is unknown. In this case we don't want to squiggle the type checking files.
abstract IsIncompleteTypeCheckEnvironment : bool

/// target framework moniker
abstract TargetFrameworkMoniker : string

/// Project Guid
abstract ProjectGuid : string

/// timestamp the site was last loaded
abstract LoadTime : System.DateTime

abstract ProjectProvider : IProvideProjectSite option
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ open Microsoft.FSharp.Compiler.CompileOps
open Microsoft.FSharp.Compiler.SourceCodeServices
open Microsoft.VisualStudio
open Microsoft.VisualStudio.Editor
open Microsoft.VisualStudio.FSharp.LanguageService
open Microsoft.VisualStudio.FSharp.LanguageService.SiteProvider
open Microsoft.VisualStudio.FSharp.Editor.SiteProvider
open Microsoft.VisualStudio.TextManager.Interop
open Microsoft.VisualStudio.LanguageServices
open Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
Expand Down
Loading