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

Commit02af98e

Browse files
committed
Code cleanup for brace completion
1 parente71bcc8 commit02af98e

File tree

3 files changed

+77
-93
lines changed

3 files changed

+77
-93
lines changed

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

Lines changed: 73 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
namespaceMicrosoft.VisualStudio.FSharp.Editor
44

5+
// This implementation does not rely on Roslyn internals.
6+
57
openSystem
68
openSystem.Diagnostics
79
openSystem.Threading
810
openSystem.ComponentModel.Composition
9-
10-
openMicrosoft.CodeAnalysis
11-
openMicrosoft.CodeAnalysis.Text
12-
openMicrosoft.CodeAnalysis.Editor.Shared.Utilities
13-
openMicrosoft.CodeAnalysis.Host
14-
openMicrosoft.CodeAnalysis.Host.Mef
15-
openMicrosoft.CodeAnalysis.Classification
1611
openMicrosoft.VisualStudio.Text.BraceCompletion
1712
openMicrosoft.VisualStudio.Text.Operations
1813
openMicrosoft.VisualStudio.Text
1914
openMicrosoft.VisualStudio.Text.Editor
2015
openMicrosoft.VisualStudio.Utilities
16+
openMicrosoft.CodeAnalysis
17+
openMicrosoft.CodeAnalysis.Text
18+
openMicrosoft.CodeAnalysis.Host
19+
openMicrosoft.CodeAnalysis.Host.Mef
20+
openMicrosoft.CodeAnalysis.Classification
2121

2222
[<AutoOpen>]
23-
moduleprivateFSharpBraceCompletionSessionProviderHelpers=
23+
moduleBraceCompletionSessionProviderHelpers=
2424

2525
letgetLanguageService<'Twhen'T:>ILanguageServiceand'T:null>(document:Document)=
2626
match document.Projectwith
@@ -37,11 +37,20 @@ module private FSharpBraceCompletionSessionProviderHelpers =
3737
letgetCaretPosition session=
3838
session|> getCaretPoint session.SubjectBuffer
3939

40+
lettryInsertAdditionalBracePair(session:IBraceCompletionSession)openingChar closingChar=
41+
letsourceCode= session.TextView.TextSnapshot
42+
letposition= session.TextView.Caret.Position.BufferPosition.Position
43+
letstart= position-2
44+
letend'= position
45+
46+
start>=0&& end'< sourceCode.Length&&
47+
sourceCode.GetText(start,1).[0]= openingChar&& sourceCode.GetText(end',1).[0]= closingChar
48+
4049
[<Literal>]
4150
letBraceCompletion="Brace_Completion"
4251

4352
[<AllowNullLiteral>]
44-
typeinternalIEditorBraceCompletionSession=
53+
typeIEditorBraceCompletionSession=
4554
inherit ILanguageService
4655

4756
abstractCheckOpeningPoint :IBraceCompletionSession*CancellationToken->bool
@@ -53,12 +62,12 @@ type internal IEditorBraceCompletionSession =
5362
abstractAfterReturn :IBraceCompletionSession*CancellationToken->unit
5463

5564
[<AllowNullLiteral>]
56-
typeinternalIEditorBraceCompletionSessionFactory=
65+
typeIEditorBraceCompletionSessionFactory=
5766
inherit ILanguageService
5867

5968
abstractTryCreateSession :Document* openingPosition:int* openingBrace:char*CancellationToken->IEditorBraceCompletionSession
6069

61-
typeinternalFSharpBraceCompletionSession
70+
typeBraceCompletionSession
6271
(
6372
textView: ITextView,
6473
subjectBuffer: ITextBuffer,
@@ -74,7 +83,7 @@ type internal FSharpBraceCompletionSession
7483
let mutableopeningPoint:ITrackingPoint=null
7584
leteditorOperations= editorOperationsFactoryService.GetEditorOperations(textView)
7685

77-
memberthis.EndSession()=
86+
member__.EndSession()=
7887
closingPoint<-null
7988
openingPoint<-null
8089

@@ -142,7 +151,7 @@ type internal FSharpBraceCompletionSession
142151

143152
undo.Complete()
144153

145-
memberthis.HasNoForwardTyping(caretPoint:SnapshotPoint,endPoint:SnapshotPoint)=
154+
member__.HasNoForwardTyping(caretPoint:SnapshotPoint,endPoint:SnapshotPoint)=
146155
Debug.Assert(caretPoint.Snapshot= endPoint.Snapshot,"snapshots do not match")
147156

148157
if caretPoint.Snapshot= endPoint.Snapshotthen
@@ -304,31 +313,31 @@ type internal FSharpBraceCompletionSession
304313

305314
member__.TextView= textView
306315

307-
moduleprivateParenthesis=
316+
moduleParenthesis=
308317

309318
[<Literal>]
310319
letOpenCharacter='('
311320

312321
[<Literal>]
313322
letCloseCharacter=')'
314323

315-
moduleprivateCurlyBrackets=
324+
moduleCurlyBrackets=
316325

317326
[<Literal>]
318327
letOpenCharacter='{'
319328

320329
[<Literal>]
321330
letCloseCharacter='}'
322331

323-
moduleprivateSquareBrackets=
332+
moduleSquareBrackets=
324333

325334
[<Literal>]
326335
letOpenCharacter='['
327336

328337
[<Literal>]
329338
letCloseCharacter=']'
330339

331-
moduleprivateDoubleQuote=
340+
moduleDoubleQuote=
332341

333342
[<Literal>]
334343
letOpenCharacter='"'
@@ -338,7 +347,7 @@ module private DoubleQuote =
338347

339348
(* This is for [| |] and {| |} , since the implementation deals with chars only.
340349
We have to test if there is a { or [ before the cursor position and insert the closing '|'.*)
341-
moduleprivateVerticalBar=
350+
moduleVerticalBar=
342351

343352
[<Literal>]
344353
letOpenCharacter='|'
@@ -348,7 +357,7 @@ module private VerticalBar =
348357

349358
(* This is for attributes [< >] , since the implementation deals with chars only.
350359
We have to test if there is a [ before the cursor position and insert the closing '>'.*)
351-
moduleprivateAngleBrackets=
360+
moduleAngleBrackets=
352361

353362
[<Literal>]
354363
letOpenCharacter='<'
@@ -357,126 +366,104 @@ module private AngleBrackets =
357366
letCloseCharacter='>'
358367

359368
(* For multiline comments like this, since the implementation deals with chars only*)
360-
moduleprivateAsterisk=
369+
moduleAsterisk=
361370

362371
[<Literal>]
363372
letOpenCharacter='*'
364373

365374
[<Literal>]
366375
letCloseCharacter='*'
367376

368-
369-
typeinternalParenthesisCompletionSession()=
377+
typeParenthesisCompletionSession()=
370378

371379
interface IEditorBraceCompletionSessionwith
372380

373-
memberthis.AfterReturn(_session,_cancellationToken)=
381+
member__.AfterReturn(_session,_cancellationToken)=
374382
()
375383

376-
memberthis.AfterStart(_session,_cancellationToken)=
384+
member__.AfterStart(_session,_cancellationToken)=
377385
()
378386

379-
memberthis.AllowOverType(_session,_cancellationToken)=
380-
// TODO: Implement this for F#
387+
member__.AllowOverType(_session,_cancellationToken)=
381388
true
382389

383-
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
384-
// TODO: Implement this for F#
390+
member__.CheckOpeningPoint(_session,_cancellationToken)=
385391
true
386392

387-
typeinternalDoubleQuoteCompletionSession()=
393+
typeDoubleQuoteCompletionSession()=
388394

389395
interface IEditorBraceCompletionSessionwith
390396

391-
memberthis.AfterReturn(_session,_cancellationToken)=
397+
member__.AfterReturn(_session,_cancellationToken)=
392398
()
393399

394-
memberthis.AfterStart(_session,_cancellationToken)=
400+
member__.AfterStart(_session,_cancellationToken)=
395401
()
396402

397-
memberthis.AllowOverType(_session,_cancellationToken)=
398-
// TODO: Implement this for F#
403+
member__.AllowOverType(_session,_cancellationToken)=
399404
true
400405

401-
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
402-
// TODO: Implement this for F#
406+
member__.CheckOpeningPoint(_session,_cancellationToken)=
403407
true
404408

405-
typeinternalVerticalBarCompletionSession()=
409+
typeVerticalBarCompletionSession()=
406410

407411
interface IEditorBraceCompletionSessionwith
408412

409-
memberthis.AfterReturn(_session,_cancellationToken)=
413+
member__.AfterReturn(_session,_cancellationToken)=
410414
()
411415

412-
memberthis.AfterStart(_session,_cancellationToken)=
416+
member__.AfterStart(_session,_cancellationToken)=
413417
()
414418

415-
memberthis.AllowOverType(_session,_cancellationToken)=
416-
// TODO: Implement this for F#
419+
member__.AllowOverType(_session,_cancellationToken)=
417420
true
418421

419422
(* This is for [| |] and {| |} , since the implementation deals with chars only.
420423
We have to test if there is a { or [ before the cursor position and insert the closing '|'.*)
421-
memberthis.CheckOpeningPoint(_session,_cancellationToken)=
422-
letsourceCode=_session.TextView.TextSnapshot
423-
//let document = _session.TextView.TextSnapshot.GetOpenDocumentInCurrentContextWithChanges()
424-
letposition=_session.TextView.Caret.Position.BufferPosition.Position
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)="]")
428-
ret
429-
430-
typeinternalAngleBracketCompletionSession()=
424+
member__.CheckOpeningPoint(session,_cancellationToken)=
425+
tryInsertAdditionalBracePair session CurlyBrackets.OpenCharacter CurlyBrackets.CloseCharacter||
426+
tryInsertAdditionalBracePair session SquareBrackets.OpenCharacter SquareBrackets.CloseCharacter
427+
428+
typeAngleBracketCompletionSession()=
431429

432430
interface IEditorBraceCompletionSessionwith
433431

434-
memberthis.AfterReturn(_session,_cancellationToken)=
432+
member__.AfterReturn(_session,_cancellationToken)=
435433
()
436434

437-
memberthis.AfterStart(_session,_cancellationToken)=
435+
member__.AfterStart(_session,_cancellationToken)=
438436
()
439437

440-
memberthis.AllowOverType(_session,_cancellationToken)=
441-
// TODO: Implement this for F#
438+
member__.AllowOverType(_session,_cancellationToken)=
442439
true
443440

444441
(* This is for attributes [< >] , since the implementation deals with chars only.
445442
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
443+
member__.CheckOpeningPoint(session,_cancellationToken)=
444+
tryInsertAdditionalBracePair session SquareBrackets.OpenCharacter SquareBrackets.CloseCharacter
452445

453446
(* For multi-line comments, test if it is between "()"*)
454-
typeinternalAsteriskCompletionSession()=
447+
typeAsteriskCompletionSession()=
455448

456449
interface IEditorBraceCompletionSessionwith
457450

458-
memberthis.AfterReturn(_session,_cancellationToken)=
451+
member__.AfterReturn(_session,_cancellationToken)=
459452
()
460453

461-
memberthis.AfterStart(_session,_cancellationToken)=
454+
member__.AfterStart(_session,_cancellationToken)=
462455
()
463456

464-
memberthis.AllowOverType(_session,_cancellationToken)=
465-
// TODO: Implement this for F#
457+
member__.AllowOverType(_session,_cancellationToken)=
466458
true
467459

468460
(* This is for attributes [< >] , since the implementation deals with chars only.
469461
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
462+
member__.CheckOpeningPoint(session,_cancellationToken)=
463+
tryInsertAdditionalBracePair session Parenthesis.OpenCharacter Parenthesis.CloseCharacter
476464

477465
[<ExportLanguageService(typeof<IEditorBraceCompletionSessionFactory>, FSharpConstants.FSharpLanguageName)>]
478-
typeinternalFSharpEditorBraceCompletionSessionFactory()=
479-
inherit ForegroundThreadAffinitizedObject()
466+
typeEditorBraceCompletionSessionFactory()=
480467

481468
member__.IsSupportedOpeningBrace openingBrace=
482469
match openingBracewith
@@ -485,26 +472,25 @@ type internal FSharpEditorBraceCompletionSessionFactory () =
485472
| Asterisk.OpenCharacter->true
486473
|_->false
487474

488-
memberthis.CheckCodeContext(_document:Document,_position:int,_openingBrace,_cancellationToken)=
489-
this.AssertIsForeground()
490-
// We need to know if we are inside a F# comment. If we are, then don't do automatic completion.
491-
letsourceCodeTask=_document.GetTextAsync(_cancellationToken)
492-
sourceCodeTask.Wait(_cancellationToken)
475+
member__.CheckCodeContext(document:Document,position:int,_openingBrace,cancellationToken)=
476+
// We need to know if we are inside a F# comment. If we are, then don't do automatic completion.
477+
letsourceCodeTask= document.GetTextAsync(cancellationToken)
478+
sourceCodeTask.Wait(cancellationToken)
493479
letsourceCode= sourceCodeTask.Result
494480

495-
_position=0
496-
||letcolorizationData= Tokenizer.getColorizationData(_document.Id, sourceCode, TextSpan(_position-1,1), Some(_document.FilePath),[],_cancellationToken)
481+
position=0
482+
||letcolorizationData= Tokenizer.getClassifiedSpans(document.Id, sourceCode, TextSpan(position-1,1), Some(document.FilePath),[],cancellationToken)
497483
in colorizationData.Count=0
498-
|| colorizationData.Exists(fun classifiedSpan->
499-
classifiedSpan.TextSpan.IntersectsWith_position&&
484+
|| colorizationData.Exists(fun classifiedSpan->
485+
classifiedSpan.TextSpan.IntersectsWithposition&&
500486
(
501487
match classifiedSpan.ClassificationTypewith
502488
| ClassificationTypeNames.Comment
503489
| ClassificationTypeNames.StringLiteral->false
504490
|_->true// anything else is a valid classification type
505491
))
506492

507-
memberthis.CreateEditorSession(_document:Document,_openingPosition:int,openingBrace:char,_cancellationToken:CancellationToken)=
493+
member__.CreateEditorSession(_document,_openingPosition,openingBrace,_cancellationToken)=
508494
match openingBracewith
509495
| Parenthesis.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
510496
| CurlyBrackets.OpenCharacter-> ParenthesisCompletionSession():> IEditorBraceCompletionSession
@@ -517,9 +503,7 @@ type internal FSharpEditorBraceCompletionSessionFactory () =
517503

518504
interface IEditorBraceCompletionSessionFactorywith
519505

520-
memberthis.TryCreateSession(document,openingPosition,openingBrace,cancellationToken):IEditorBraceCompletionSession=
521-
this.AssertIsForeground()
522-
506+
memberthis.TryCreateSession(document,openingPosition,openingBrace,cancellationToken)=
523507
if this.IsSupportedOpeningBrace(openingBrace)&& this.CheckCodeContext(document, openingPosition, openingBrace, cancellationToken)then
524508
this.CreateEditorSession(document, openingPosition, openingBrace, cancellationToken)
525509
else
@@ -534,20 +518,16 @@ type internal FSharpEditorBraceCompletionSessionFactory () =
534518
[<BracePair(VerticalBar.OpenCharacter, VerticalBar.CloseCharacter)>]
535519
[<BracePair(AngleBrackets.OpenCharacter, AngleBrackets.CloseCharacter)>]
536520
[<BracePair(Asterisk.OpenCharacter, Asterisk.CloseCharacter)>]
537-
typeinternalFSharpBraceCompletionSessionProvider
521+
typeBraceCompletionSessionProvider
538522
[<ImportingConstructor>]
539523
(
540524
undoManager: ITextBufferUndoManagerProvider,
541525
editorOperationsFactoryService: IEditorOperationsFactoryService
542526
)=
543527

544-
inherit ForegroundThreadAffinitizedObject()
545-
546528
interface IBraceCompletionSessionProviderwith
547529

548-
memberthis.TryCreateSession(textView,openingPoint,openingBrace,closingBrace,session)=
549-
this.AssertIsForeground();
550-
530+
member__.TryCreateSession(textView,openingPoint,openingBrace,closingBrace,session)=
551531
lettextSnapshot= openingPoint.Snapshot
552532

553533
letnewSession=
@@ -564,7 +544,7 @@ type internal FSharpBraceCompletionSessionProvider
564544
|null->null
565545
| editorSession->
566546
letundoHistory= undoManager.GetTextBufferUndoManager(textView.TextBuffer).TextBufferUndoHistory
567-
FSharpBraceCompletionSession(
547+
BraceCompletionSession(
568548
textView,
569549
openingPoint.Snapshot.TextBuffer,
570550
openingPoint,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespaceMicrosoft.VisualStudio.FSharp.Editor

‎vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<CompileInclude="CodeFix\FixIndexerAccess.fs" />
9999
<CompileInclude="CodeFix\RenameParamToMatchSignature.fs" />
100100
<CompileInclude="Build\SetGlobalPropertiesForSdkProjects.fs" />
101+
<CompileInclude="AutomaticCompletion\BraceCompletionSessionProvider.fsi" />
101102
<CompileInclude="AutomaticCompletion\BraceCompletionSessionProvider.fs" />
102103
</ItemGroup>
103104

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp