Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit685d2d8

Browse files
committed
Added Parenthesis for brace completion
1 parent3d47f4e commit685d2d8

File tree

1 file changed

+80
-9
lines changed

1 file changed

+80
-9
lines changed

‎vsintegration/src/FSharp.Editor/AutomaticCompletion/BraceCompletionSessionProvider.fs‎

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ open Microsoft.VisualStudio.Text
3030
openMicrosoft.VisualStudio.Text.Editor
3131
openSystem.Diagnostics
3232
openSystem.Runtime.InteropServices
33+
openSystem.Composition
34+
openMicrosoft.CodeAnalysis.Host.Mef
35+
openMicrosoft.VisualStudio.Utilities
3336

3437
[<AutoOpen>]
3538
moduleprivateFSharpBraceCompletionSessionProviderHelpers=
36-
openSystem.Runtime.InteropServices
3739

3840
letgetLanguageService<'Twhen'T:>ILanguageServiceand'T:null>(document:Document)=
3941
match document.Projectwith
@@ -71,7 +73,7 @@ type internal IEditorBraceCompletionSessionFactory =
7173

7274
abstractTryCreateSession :Document* openingPosition:int* openingBrace:char*CancellationToken->IEditorBraceCompletionSession
7375

74-
typeinternalBraceCompletionSession
76+
typeinternalFSharpBraceCompletionSession
7577
(
7678
textView: ITextView,
7779
subjectBuffer: ITextBuffer,
@@ -192,7 +194,6 @@ type internal BraceCompletionSession
192194

193195
if afterBrace.HasValuethen
194196
textView.Caret.MoveTo(afterBrace.Value)|> ignore
195-
196197

197198
interface IBraceCompletionSessionwith
198199

@@ -316,17 +317,79 @@ type internal BraceCompletionSession
316317

317318
member__.TextView= textView
318319

319-
typeinternalBraceCompletionSessionProvider
320+
moduleprivateParenthesis=
321+
322+
[<Literal>]
323+
letOpenCharacter='('
324+
325+
[<Literal>]
326+
letCloseCharacter=')'
327+
328+
typeinternalParenthesisCompletionSession()=
329+
330+
interface IEditorBraceCompletionSessionwith
331+
332+
memberthis.AfterReturn(_session,_cancellationToken)=
333+
()
334+
335+
memberthis.AfterStart(_session,_cancellationToken)=
336+
()
337+
338+
memberthis.AllowOverType(_session,_cancellationToken)=
339+
// TODO: Implement this for F#
340+
true
341+
342+
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
343+
// TODO: Implement this for F#
344+
true
345+
346+
[<Shared>]
347+
[<ExportLanguageService(typeof<IEditorBraceCompletionSessionFactory>, FSharpConstants.FSharpLanguageName)>]
348+
typeinternalFSharpEditorBraceCompletionSessionFactory
349+
[<ImportingConstructor>](_smartIndetationService: ISmartIndentationService,_undoManager: ITextBufferUndoManagerProvider)=
350+
inherit ForegroundThreadAffinitizedObject()
351+
352+
member__.IsSupportedOpeningBrace openingBrace=
353+
match openingBracewith
354+
| Parenthesis.OpenCharacter->true
355+
|_->false
356+
357+
memberthis.CheckCodeContext(_document,_position,_openingBrace,_cancellationToken)=
358+
this.AssertIsForeground();
359+
360+
// TODO: We need to know if we are inside a F# comment. If we are, then don't do automatic completion.
361+
true
362+
363+
memberthis.CreateEditorSession(_document:Document,_openingPosition:int,openingBrace:char,_cancellationToken:CancellationToken)=
364+
match openingBracewith
365+
| Parenthesis.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
366+
|_->null
367+
368+
interface IEditorBraceCompletionSessionFactorywith
369+
370+
memberthis.TryCreateSession(document,openingPosition,openingBrace,cancellationToken):IEditorBraceCompletionSession=
371+
this.AssertIsForeground()
372+
373+
if this.IsSupportedOpeningBrace(openingBrace)&& this.CheckCodeContext(document, openingPosition, openingBrace, cancellationToken)then
374+
this.CreateEditorSession(document, openingPosition, openingBrace, cancellationToken)
375+
else
376+
null
377+
378+
[<Export(typeof<IBraceCompletionSessionProvider>)>]
379+
[<ContentType(FSharpConstants.FSharpContentTypeName)>]
380+
[<BracePair(Parenthesis.OpenCharacter, Parenthesis.CloseCharacter)>]
381+
typeinternalFSharpBraceCompletionSessionProvider
382+
[<ImportingConstructor>]
320383
(
321384
undoManager: ITextBufferUndoManagerProvider,
322-
_editorOperationsFactoryService: IEditorOperationsFactoryService
385+
editorOperationsFactoryService: IEditorOperationsFactoryService
323386
)=
324387

325388
inherit ForegroundThreadAffinitizedObject()
326389

327390
interface IBraceCompletionSessionProviderwith
328391

329-
memberthis.TryCreateSession(textView,openingPoint,openingBrace,_closingBrace,session)=
392+
memberthis.TryCreateSession(textView,openingPoint,openingBrace,closingBrace,session)=
330393
this.AssertIsForeground();
331394

332395
lettextSnapshot= openingPoint.Snapshot
@@ -343,9 +406,17 @@ type internal BraceCompletionSessionProvider
343406

344407
match editorSessionFactory.TryCreateSession(document, openingPoint.Position, openingBrace, cancellationToken)with
345408
|null->null
346-
|_editorSession->
347-
let_undoHistory= undoManager.GetTextBufferUndoManager(textView.TextBuffer).TextBufferUndoHistory
348-
null
409+
| editorSession->
410+
letundoHistory= undoManager.GetTextBufferUndoManager(textView.TextBuffer).TextBufferUndoHistory
411+
FSharpBraceCompletionSession(
412+
textView,
413+
openingPoint.Snapshot.TextBuffer,
414+
openingPoint,
415+
openingBrace,
416+
closingBrace,
417+
undoHistory,
418+
editorOperationsFactoryService,
419+
editorSession):> IBraceCompletionSession
349420

350421
match sessionwith
351422
|null->false

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp