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

Commite71bcc8

Browse files
gibranrosaTIHan
authored andcommitted
Fixes for typing "|" at the beginning and end, implemented [<>] and (**) completion
1 parent20d3ba0 commite71bcc8

File tree

1 file changed

+95
-15
lines changed

1 file changed

+95
-15
lines changed

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

Lines changed: 95 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ module private DoubleQuote =
336336
[<Literal>]
337337
letCloseCharacter='"'
338338

339+
(* This is for [| |] and {| |} , since the implementation deals with chars only.
340+
We have to test if there is a { or [ before the cursor position and insert the closing '|'.*)
339341
moduleprivateVerticalBar=
340342

341343
[<Literal>]
@@ -344,6 +346,26 @@ module private VerticalBar =
344346
[<Literal>]
345347
letCloseCharacter='|'
346348

349+
(* This is for attributes [< >] , since the implementation deals with chars only.
350+
We have to test if there is a [ before the cursor position and insert the closing '>'.*)
351+
moduleprivateAngleBrackets=
352+
353+
[<Literal>]
354+
letOpenCharacter='<'
355+
356+
[<Literal>]
357+
letCloseCharacter='>'
358+
359+
(* For multiline comments like this, since the implementation deals with chars only*)
360+
moduleprivateAsterisk=
361+
362+
[<Literal>]
363+
letOpenCharacter='*'
364+
365+
[<Literal>]
366+
letCloseCharacter='*'
367+
368+
347369
typeinternalParenthesisCompletionSession()=
348370

349371
interface IEditorBraceCompletionSessionwith
@@ -393,48 +415,104 @@ type internal VerticalBarCompletionSession () =
393415
memberthis.AllowOverType(_session,_cancellationToken)=
394416
// TODO: Implement this for F#
395417
true
396-
418+
419+
(* This is for [| |] and {| |} , since the implementation deals with chars only.
420+
We have to test if there is a { or [ before the cursor position and insert the closing '|'.*)
397421
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
398422
letsourceCode=_session.TextView.TextSnapshot
399423
//let document = _session.TextView.TextSnapshot.GetOpenDocumentInCurrentContextWithChanges()
400424
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)="]"
425+
letret= position-2>=0&& position< sourceCode.Length&&
426+
(sourceCode.GetText(position-2,1)="{"&& sourceCode.GetText(position,1)="}"
427+
|| sourceCode.GetText(position-2,1)="["&& sourceCode.GetText(position,1)="]")
403428
ret
404-
429+
430+
typeinternalAngleBracketCompletionSession()=
431+
432+
interface IEditorBraceCompletionSessionwith
433+
434+
memberthis.AfterReturn(_session,_cancellationToken)=
435+
()
436+
437+
memberthis.AfterStart(_session,_cancellationToken)=
438+
()
439+
440+
memberthis.AllowOverType(_session,_cancellationToken)=
441+
// TODO: Implement this for F#
442+
true
443+
444+
(* This is for attributes [< >] , since the implementation deals with chars only.
445+
We have to test if there is a [ before the cursor position and insert the closing '>'.*)
446+
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
447+
letsourceCode=_session.TextView.TextSnapshot
448+
letposition=_session.TextView.Caret.Position.BufferPosition.Position
449+
letret= position-2>=0&& position< sourceCode.Length&&
450+
sourceCode.GetText(position-2,1).Equals("[")&& sourceCode.GetText(position,1).Equals("]")
451+
ret
452+
453+
(* For multi-line comments, test if it is between "()"*)
454+
typeinternalAsteriskCompletionSession()=
455+
456+
interface IEditorBraceCompletionSessionwith
457+
458+
memberthis.AfterReturn(_session,_cancellationToken)=
459+
()
460+
461+
memberthis.AfterStart(_session,_cancellationToken)=
462+
()
463+
464+
memberthis.AllowOverType(_session,_cancellationToken)=
465+
// TODO: Implement this for F#
466+
true
467+
468+
(* This is for attributes [< >] , since the implementation deals with chars only.
469+
We have to test if there is a [ before the cursor position and insert the closing '>'.*)
470+
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
471+
letsourceCode=_session.TextView.TextSnapshot
472+
letposition=_session.TextView.Caret.Position.BufferPosition.Position
473+
letret= position-2>=0&& position< sourceCode.Length&&
474+
sourceCode.GetText(position-2,1).Equals("(")&& sourceCode.GetText(position,1).Equals(")")
475+
ret
476+
405477
[<ExportLanguageService(typeof<IEditorBraceCompletionSessionFactory>, FSharpConstants.FSharpLanguageName)>]
406478
typeinternalFSharpEditorBraceCompletionSessionFactory()=
407479
inherit ForegroundThreadAffinitizedObject()
408480

409481
member__.IsSupportedOpeningBrace openingBrace=
410482
match openingBracewith
411483
| Parenthesis.OpenCharacter| CurlyBrackets.OpenCharacter| SquareBrackets.OpenCharacter
412-
| DoubleQuote.OpenCharacter| VerticalBar.OpenCharacter->true
484+
| DoubleQuote.OpenCharacter| VerticalBar.OpenCharacter| AngleBrackets.OpenCharacter
485+
| Asterisk.OpenCharacter->true
413486
|_->false
414487

415488
memberthis.CheckCodeContext(_document:Document,_position:int,_openingBrace,_cancellationToken)=
416489
this.AssertIsForeground()
417-
//TODO:We need to know if we are inside a F# comment. If we are, then don't do automatic completion.
490+
// We need to know if we are inside a F# comment. If we are, then don't do automatic completion.
418491
letsourceCodeTask=_document.GetTextAsync(_cancellationToken)
419492
sourceCodeTask.Wait(_cancellationToken)
420493
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-
))
494+
495+
_position=0
496+
||letcolorizationData= Tokenizer.getColorizationData(_document.Id, sourceCode, TextSpan(_position-1,1), Some(_document.FilePath),[],_cancellationToken)
497+
in colorizationData.Count=0
498+
|| colorizationData.Exists(fun classifiedSpan->
499+
classifiedSpan.TextSpan.IntersectsWith_position&&
500+
(
501+
match classifiedSpan.ClassificationTypewith
502+
| ClassificationTypeNames.Comment
503+
| ClassificationTypeNames.StringLiteral->false
504+
|_->true// anything else is a valid classification type
505+
))
430506

431507
memberthis.CreateEditorSession(_document:Document,_openingPosition:int,openingBrace:char,_cancellationToken:CancellationToken)=
432508
match openingBracewith
433509
| Parenthesis.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
434510
| CurlyBrackets.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
435511
| SquareBrackets.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
436512
| VerticalBar.OpenCharacter-> VerticalBarCompletionSession():> IEditorBraceCompletionSession
513+
| AngleBrackets.OpenCharacter-> AngleBracketCompletionSession():> IEditorBraceCompletionSession
437514
| DoubleQuote.OpenCharacter-> DoubleQuoteCompletionSession():> IEditorBraceCompletionSession
515+
| Asterisk.OpenCharacter-> DoubleQuoteCompletionSession():> IEditorBraceCompletionSession
438516
|_->null
439517

440518
interface IEditorBraceCompletionSessionFactorywith
@@ -454,6 +532,8 @@ type internal FSharpEditorBraceCompletionSessionFactory () =
454532
[<BracePair(SquareBrackets.OpenCharacter, SquareBrackets.CloseCharacter)>]
455533
[<BracePair(DoubleQuote.OpenCharacter, DoubleQuote.CloseCharacter)>]
456534
[<BracePair(VerticalBar.OpenCharacter, VerticalBar.CloseCharacter)>]
535+
[<BracePair(AngleBrackets.OpenCharacter, AngleBrackets.CloseCharacter)>]
536+
[<BracePair(Asterisk.OpenCharacter, Asterisk.CloseCharacter)>]
457537
typeinternalFSharpBraceCompletionSessionProvider
458538
[<ImportingConstructor>]
459539
(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp