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

Commit20d3ba0

Browse files
gibranrosaTIHan
authored andcommitted
Added Curly, Square brackets, Double quotes and [||]
1 parent24f2cc5 commit20d3ba0

File tree

1 file changed

+98
-7
lines changed

1 file changed

+98
-7
lines changed

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

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open Microsoft.CodeAnalysis.Text
1212
openMicrosoft.CodeAnalysis.Editor.Shared.Utilities
1313
openMicrosoft.CodeAnalysis.Host
1414
openMicrosoft.CodeAnalysis.Host.Mef
15-
15+
openMicrosoft.CodeAnalysis.Classification
1616
openMicrosoft.VisualStudio.Text.BraceCompletion
1717
openMicrosoft.VisualStudio.Text.Operations
1818
openMicrosoft.VisualStudio.Text
@@ -312,6 +312,38 @@ module private Parenthesis =
312312
[<Literal>]
313313
letCloseCharacter=')'
314314

315+
moduleprivateCurlyBrackets=
316+
317+
[<Literal>]
318+
letOpenCharacter='{'
319+
320+
[<Literal>]
321+
letCloseCharacter='}'
322+
323+
moduleprivateSquareBrackets=
324+
325+
[<Literal>]
326+
letOpenCharacter='['
327+
328+
[<Literal>]
329+
letCloseCharacter=']'
330+
331+
moduleprivateDoubleQuote=
332+
333+
[<Literal>]
334+
letOpenCharacter='"'
335+
336+
[<Literal>]
337+
letCloseCharacter='"'
338+
339+
moduleprivateVerticalBar=
340+
341+
[<Literal>]
342+
letOpenCharacter='|'
343+
344+
[<Literal>]
345+
letCloseCharacter='|'
346+
315347
typeinternalParenthesisCompletionSession()=
316348

317349
interface IEditorBraceCompletionSessionwith
@@ -330,24 +362,79 @@ type internal ParenthesisCompletionSession () =
330362
// TODO: Implement this for F#
331363
true
332364

365+
typeinternalDoubleQuoteCompletionSession()=
366+
367+
interface IEditorBraceCompletionSessionwith
368+
369+
memberthis.AfterReturn(_session,_cancellationToken)=
370+
()
371+
372+
memberthis.AfterStart(_session,_cancellationToken)=
373+
()
374+
375+
memberthis.AllowOverType(_session,_cancellationToken)=
376+
// TODO: Implement this for F#
377+
true
378+
379+
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
380+
// TODO: Implement this for F#
381+
true
382+
383+
typeinternalVerticalBarCompletionSession()=
384+
385+
interface IEditorBraceCompletionSessionwith
386+
387+
memberthis.AfterReturn(_session,_cancellationToken)=
388+
()
389+
390+
memberthis.AfterStart(_session,_cancellationToken)=
391+
()
392+
393+
memberthis.AllowOverType(_session,_cancellationToken)=
394+
// TODO: Implement this for F#
395+
true
396+
397+
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
398+
letsourceCode=_session.TextView.TextSnapshot
399+
//let document = _session.TextView.TextSnapshot.GetOpenDocumentInCurrentContextWithChanges()
400+
letposition=_session.TextView.Caret.Position.BufferPosition.Position
401+
letret= sourceCode.GetText(position-2,1)="{"&& sourceCode.GetText(position,1)="}"
402+
|| sourceCode.GetText(position-2,1)="["&& sourceCode.GetText(position,1)="]"
403+
ret
404+
333405
[<ExportLanguageService(typeof<IEditorBraceCompletionSessionFactory>, FSharpConstants.FSharpLanguageName)>]
334406
typeinternalFSharpEditorBraceCompletionSessionFactory()=
335407
inherit ForegroundThreadAffinitizedObject()
336408

337409
member__.IsSupportedOpeningBrace openingBrace=
338410
match openingBracewith
339-
| Parenthesis.OpenCharacter->true
411+
| Parenthesis.OpenCharacter| CurlyBrackets.OpenCharacter| SquareBrackets.OpenCharacter
412+
| DoubleQuote.OpenCharacter| VerticalBar.OpenCharacter->true
340413
|_->false
341414

342-
memberthis.CheckCodeContext(_document,_position,_openingBrace,_cancellationToken)=
343-
this.AssertIsForeground();
344-
345-
// TODO: We need to know if we are inside a F# comment. If we are, then don't do automatic completion.
346-
true
415+
memberthis.CheckCodeContext(_document:Document,_position:int,_openingBrace,_cancellationToken)=
416+
this.AssertIsForeground()
417+
// TODO: We need to know if we are inside a F# comment. If we are, then don't do automatic completion.
418+
letsourceCodeTask=_document.GetTextAsync(_cancellationToken)
419+
sourceCodeTask.Wait(_cancellationToken)
420+
letsourceCode= sourceCodeTask.Result
421+
letcolorizationData= Tokenizer.getColorizationData(_document.Id, sourceCode, TextSpan(_position-1,1), Some(_document.FilePath),[],_cancellationToken)
422+
colorizationData.Exists(fun classifiedSpan->
423+
classifiedSpan.TextSpan.IntersectsWith_position&&
424+
(
425+
match classifiedSpan.ClassificationTypewith
426+
| ClassificationTypeNames.Comment
427+
| ClassificationTypeNames.StringLiteral->false
428+
|_->true// anything else is a valid classification type
429+
))
347430

348431
memberthis.CreateEditorSession(_document:Document,_openingPosition:int,openingBrace:char,_cancellationToken:CancellationToken)=
349432
match openingBracewith
350433
| Parenthesis.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
434+
| CurlyBrackets.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
435+
| SquareBrackets.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
436+
| VerticalBar.OpenCharacter-> VerticalBarCompletionSession():> IEditorBraceCompletionSession
437+
| DoubleQuote.OpenCharacter-> DoubleQuoteCompletionSession():> IEditorBraceCompletionSession
351438
|_->null
352439

353440
interface IEditorBraceCompletionSessionFactorywith
@@ -363,6 +450,10 @@ type internal FSharpEditorBraceCompletionSessionFactory () =
363450
[<Export(typeof<IBraceCompletionSessionProvider>)>]
364451
[<ContentType(FSharpConstants.FSharpContentTypeName)>]
365452
[<BracePair(Parenthesis.OpenCharacter, Parenthesis.CloseCharacter)>]
453+
[<BracePair(CurlyBrackets.OpenCharacter, CurlyBrackets.CloseCharacter)>]
454+
[<BracePair(SquareBrackets.OpenCharacter, SquareBrackets.CloseCharacter)>]
455+
[<BracePair(DoubleQuote.OpenCharacter, DoubleQuote.CloseCharacter)>]
456+
[<BracePair(VerticalBar.OpenCharacter, VerticalBar.CloseCharacter)>]
366457
typeinternalFSharpBraceCompletionSessionProvider
367458
[<ImportingConstructor>]
368459
(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp