|
3 | 3 | namespace Microsoft.VisualStudio.FSharp.Editor |
4 | 4 |
|
5 | 5 | open System |
6 | | -open System.Runtime.InteropServices |
7 | 6 | open Microsoft.VisualStudio |
8 | | -open Microsoft.VisualStudio.Editor |
9 | 7 | open Microsoft.VisualStudio.Shell.Interop |
10 | 8 | open Microsoft.VisualStudio.TextManager.Interop |
11 | 9 |
|
12 | 10 | /// Helper methods for interoperating with COM |
13 | | -module internal Com = |
14 | | - let ThrowOnFailure0(hr) = |
15 | | - ErrorHandler.ThrowOnFailure(hr) |> ignore |
16 | | - |
17 | | - let ThrowOnFailure1(hr,res) = |
18 | | - ErrorHandler.ThrowOnFailure(hr) |> ignore; |
19 | | - res |
20 | | - |
21 | | - let ThrowOnFailure2(hr,res1,res2) = |
22 | | - ErrorHandler.ThrowOnFailure(hr) |> ignore; |
23 | | - res1,res2 |
24 | | - |
25 | | - let ThrowOnFailure3(hr,res1,res2,res3) = |
26 | | - ErrorHandler.ThrowOnFailure(hr) |> ignore; |
27 | | - res1,res2,res3 |
28 | | - |
29 | | - let ThrowOnFailure4(hr,res1,res2,res3,res4) = |
30 | | - ErrorHandler.ThrowOnFailure(hr) |> ignore; |
31 | | - res1,res2,res3,res4 |
32 | | - |
| 11 | +module internal Com = |
33 | 12 | let Succeeded hr = |
34 | 13 | // REVIEW: Not the correct check for succeeded |
35 | 14 | hr = VSConstants.S_OK |
36 | 15 |
|
37 | | -module internal VsUserData = |
38 | | - |
39 | | - let vsBufferMoniker = Guid("978A8E17-4DF8-432A-9623-D530A26452BC") |
40 | | - |
41 | | - // This is the file name of the buffer. |
42 | | - let GetBufferMonker(ud:IVsUserData) : string = |
43 | | - downcast Com.ThrowOnFailure1(ud.GetData(ref vsBufferMoniker)) |
44 | | - |
45 | | -module internal VsTextLines = |
46 | | - /// Get the length of the given line. |
47 | | - let LengthOfLine (buffer:IVsTextBuffer) (line:int) : int = |
48 | | - Com.ThrowOnFailure1(buffer.GetLengthOfLine(line)) |
49 | | - |
50 | | - /// Get the text for a particular line. |
51 | | - let LineText (buffer:IVsTextLines) line = |
52 | | - Com.ThrowOnFailure1(buffer.GetLineText(line, 0, line, LengthOfLine buffer line)) |
53 | | - |
54 | | - /// Get the color state |
55 | | - let TextColorState (buffer:IVsTextLines) : IVsTextColorState= unbox(box(buffer)) |
56 | | - |
57 | | - /// Get the filename of the given buffer (via IVsUserData). Not all buffers have a file. This will be an exception. |
58 | | - let GetFilename(buffer : IVsTextLines) = |
59 | | - let ud = (box buffer) :?> IVsUserData |
60 | | - VsUserData.GetBufferMonker(ud) |
61 | | - |
62 | | - /// Get the string contents of a given buffer (the current snapshot). |
63 | | - let GetFileContents(buffer: IVsTextBuffer, editorAdaptersFactoryService: IVsEditorAdaptersFactoryService) = |
64 | | - let dataBuffer = editorAdaptersFactoryService.GetDataBuffer(buffer) |
65 | | - dataBuffer.CurrentSnapshot.GetText() |
66 | | - |
67 | | -module internal VsRunningDocumentTable = |
68 | | - let FindDocumentWithoutLocking(rdt:IVsRunningDocumentTable, url:string) : (IVsHierarchy * IVsTextLines) option = |
69 | | - let (hr:int, hier:IVsHierarchy, _itemid:uint32, unkData:IntPtr, _cookie:uint32) = rdt.FindAndLockDocument(uint32 _VSRDTFLAGS.RDT_NoLock, url) |
70 | | - try |
71 | | - if Com.Succeeded(hr) then |
72 | | - let bufferObject = |
73 | | - if unkData=IntPtr.Zero then null |
74 | | - else Marshal.GetObjectForIUnknown(unkData) |
75 | | - let buffer = |
76 | | - match bufferObject with |
77 | | - | :? IVsTextLines as tl -> tl |
78 | | - | _ -> null |
79 | | - Some(hier, buffer) |
80 | | - else None |
81 | | - finally |
82 | | - if IntPtr.Zero <> unkData then Marshal.Release(unkData)|>ignore |
83 | | - |
84 | 16 | [<AutoOpen>] |
85 | 17 | module internal ServiceProviderExtensions = |
86 | 18 | type internal System.IServiceProvider with |
|
0 commit comments