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

Commit67cd73e

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
#r and #load completion (dotnet#2493)
* wip* it kind of works* bug fix* remove unused code* trigger completion on /* everything works* cosmetics
1 parent85d323d commit67cd73e

File tree

4 files changed

+131
-2
lines changed

4 files changed

+131
-2
lines changed

‎vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type internal FSharpCompletionProvider
124124
letgetInfo()=
125125
letdocumentId= workspace.GetDocumentIdInCurrentContext(sourceText.Container)
126126
letdocument= workspace.CurrentSolution.GetDocument(documentId)
127-
letdefines= projectInfoManager.GetCompilationDefinesForEditingDocument(document)
127+
letdefines= projectInfoManager.GetCompilationDefinesForEditingDocument(document)
128128
(documentId, document.FilePath, defines)
129129

130130
FSharpCompletionProvider.ShouldTriggerCompletionAux(sourceText, caretPosition, trigger.Kind, getInfo)

‎vsintegration/src/FSharp.Editor/Completion/CompletionService.fs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ type internal FSharpCompletionService
2323

2424
letbuiltInProviders=
2525
ImmutableArray.Create<CompletionProvider>(
26-
FSharpCompletionProvider(workspace, serviceProvider, checkerProvider, projectInfoManager)
26+
FSharpCompletionProvider(workspace, serviceProvider, checkerProvider, projectInfoManager),
27+
ReferenceDirectiveCompletionProvider(),
28+
LoadDirectiveCompletionProvider()
2729
// we've turned off keyword completion because it does not filter suggestion depending on context.
2830
// FSharpKeywordCompletionProvider(workspace, projectInfoManager)
2931
)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
namespaceMicrosoft.VisualStudio.FSharp.Editor
4+
5+
openSystem
6+
openSystem.Collections.Immutable
7+
openSystem.Threading
8+
openSystem.Threading.Tasks
9+
openMicrosoft.CodeAnalysis
10+
openMicrosoft.CodeAnalysis.Completion
11+
openMicrosoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion.FileSystem
12+
openMicrosoft.CodeAnalysis.Text
13+
14+
openSystem.Text.RegularExpressions
15+
openSystem.IO
16+
17+
moduleinternalFileSystemCompletion=
18+
let [<Literal>]NetworkPath="\\\\"
19+
letcommitRules= ImmutableArray.Create(CharacterSetModificationRule.Create(CharacterSetModificationKind.Replace,'"','\\',',','/'))
20+
letrules= CompletionItemRules.Create(commitCharacterRules= commitRules)
21+
22+
letgetQuotedPathStart(text:SourceText,position:int,quotedPathGroup:Group)=
23+
text.Lines.GetLineFromPosition(position).Start+ quotedPathGroup.Index
24+
25+
letgetPathThroughLastSlash(text:SourceText,position:int,quotedPathGroup:Group)=
26+
PathCompletionUtilities.GetPathThroughLastSlash(
27+
quotedPath= quotedPathGroup.Value,
28+
quotedPathStart= getQuotedPathStart(text, position, quotedPathGroup),
29+
position= position)
30+
31+
letgetTextChangeSpan(text:SourceText,position:int,quotedPathGroup:Group)=
32+
PathCompletionUtilities.GetTextChangeSpan(
33+
quotedPath= quotedPathGroup.Value,
34+
quotedPathStart= getQuotedPathStart(text, position, quotedPathGroup),
35+
position= position)
36+
37+
letgetItems(provider:CompletionProvider,document:Document,position:int,allowableExtensions:string[],directiveRegex:Regex)=
38+
asyncMaybe{
39+
let!ct= liftAsync Async.CancellationToken
40+
let!text= document.GetTextAsync ct
41+
letline= text.Lines.GetLineFromPosition(position)
42+
letlineText= text.ToString(TextSpan.FromBounds(line.Start, position));
43+
letm= directiveRegex.Match lineText
44+
45+
do! Option.guard m.Success
46+
letquotedPathGroup= m.Groups.["literal"]
47+
letquotedPath= quotedPathGroup.Value;
48+
letendsWithQuote= PathCompletionUtilities.EndsWithQuote(quotedPath)
49+
50+
do! Option.guard(not(endsWithQuote&&(position>= line.Start+ m.Length)))
51+
letsnapshot= text.FindCorrespondingEditorTextSnapshot()
52+
53+
do! Option.guard(not(isNull snapshot))
54+
letfileSystem= CurrentWorkingDirectoryDiscoveryService.GetService(snapshot)
55+
56+
letsearchPaths= ImmutableArray.Create(Path.GetDirectoryName document.FilePath)
57+
58+
lethelper=
59+
FileSystemCompletionHelper(
60+
provider,
61+
getTextChangeSpan(text, position, quotedPathGroup),
62+
fileSystem,
63+
Glyph.OpenFolder,
64+
Glyph.None,
65+
searchPaths= searchPaths,
66+
allowableExtensions= allowableExtensions,
67+
itemRules= rules)
68+
69+
letpathThroughLastSlash= getPathThroughLastSlash(text, position, quotedPathGroup)
70+
letdocumentPath=if document.Project.IsSubmissionthennullelse document.FilePath
71+
return helper.GetItems(pathThroughLastSlash, documentPath)
72+
}|> Async.map(Option.defaultValue ImmutableArray.Empty)
73+
74+
letisInsertionTrigger(text:SourceText,position)=
75+
// Bring up completion when the user types a quote (i.e.: #r "), or if they type a slash
76+
// path separator character, or if they type a comma (#r "foo,version...").
77+
// Also, if they're starting a word. i.e. #r "c:\W
78+
letch= text.[position]
79+
ch='"'|| ch='\\'|| ch=','|| ch='/'||
80+
CommonCompletionUtilities.IsStartingNewWord(text, position,(fun x-> Char.IsLetter x),(fun x-> Char.IsLetterOrDigit x))
81+
82+
letgetTextChange(selectedItem:CompletionItem,ch:Nullable<char>)=
83+
// When we commit "\\" when the user types \ we have to adjust for the fact that the
84+
// controller will automatically append \ after we commit. Because of that, we don't
85+
// want to actually commit "\\" as we'll end up with "\\\". So instead we just commit
86+
// "\" and know that controller will append "\" and give us "\\".
87+
if selectedItem.DisplayText= NetworkPath&& ch= Nullable'\\'then
88+
Some(TextChange(selectedItem.Span,"\\"))
89+
else
90+
None
91+
92+
typeinternalLoadDirectiveCompletionProvider()=
93+
inherit CommonCompletionProvider()
94+
95+
letdirectiveRegex= Regex("""#load\s+(@?"*(?<literal>"[^"]*"?))""", RegexOptions.Compiled||| RegexOptions.ExplicitCapture)
96+
97+
overridethis.ProvideCompletionsAsync(context)=
98+
async{
99+
let!items= FileSystemCompletion.getItems(this, context.Document, context.Position,[|".fs";".fsx"|], directiveRegex)
100+
context.AddItems(items)
101+
}|> CommonRoslynHelpers.StartAsyncUnitAsTask context.CancellationToken
102+
103+
override__.IsInsertionTrigger(text,position,_options)= FileSystemCompletion.isInsertionTrigger(text, position)
104+
105+
override__.GetTextChangeAsync(selectedItem,ch,cancellationToken)=
106+
match FileSystemCompletion.getTextChange(selectedItem, ch)with
107+
| Some x-> Task.FromResult(Nullable x)
108+
| None->base.GetTextChangeAsync(selectedItem, ch, cancellationToken)
109+
110+
typeinternalReferenceDirectiveCompletionProvider()=
111+
inherit CommonCompletionProvider()
112+
113+
letdirectiveRegex= Regex("""#r\s+(@?"*(?<literal>"[^"]*"?))""", RegexOptions.Compiled||| RegexOptions.ExplicitCapture)
114+
115+
overridethis.ProvideCompletionsAsync(context)=
116+
async{
117+
let!items= FileSystemCompletion.getItems(this, context.Document, context.Position,[|".dll";".exe"|], directiveRegex)
118+
context.AddItems(items)
119+
}|> CommonRoslynHelpers.StartAsyncUnitAsTask context.CancellationToken
120+
121+
override__.IsInsertionTrigger(text,position,_options)= FileSystemCompletion.isInsertionTrigger(text, position)
122+
123+
override__.GetTextChangeAsync(selectedItem,ch,cancellationToken)=
124+
match FileSystemCompletion.getTextChange(selectedItem, ch)with
125+
| Some x-> Task.FromResult(Nullable x)
126+
| None->base.GetTextChangeAsync(selectedItem, ch, cancellationToken)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<CompileInclude="Diagnostics\UnusedOpensDiagnosticAnalyzer.fs" />
5353
<CompileInclude="Completion\CompletionProvider.fs" />
5454
<CompileInclude="Completion\KeywordCompletionProvider.fs" />
55+
<CompileInclude="Completion\FileSystemCompletion.fs" />
5556
<CompileInclude="Completion\CompletionService.fs" />
5657
<CompileInclude="Completion\SignatureHelp.fs" />
5758
<CompileInclude="QuickInfo\QuickInfoProvider.fs" />

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp