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

Commit6726231

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
[WIP] Keyword completion (dotnet#2436)
* add KeywordCompletionProvider* give KeywordCompletionProvider its own ShouldTriggerCompletionAux
1 parenta1cbffb commit6726231

File tree

7 files changed

+302
-37
lines changed

7 files changed

+302
-37
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,3 +1334,76 @@ tcGlobalsSystemTypeNotFound,"The system type '%s' was required but no referenced
13341334
3213,typrelMemberHasMultiplePossibleDispatchSlots,"The member '%s' matches multiple overloads of the same method.\nPlease restrict it to one of the following:%s."
13351335
3214,methodIsNotStatic,"Method or object constructor '%s' is not static"
13361336
3215,parsUnexpectedSymbolEqualsInsteadOfIn,"Unexpected symbol '=' in expression. Did you intend to use 'for x in y .. z do' instead?"
1337+
keywordDescriptionAbstract,"Indicates a method that either has no implementation in the type in which it is declared or that is virtual and has a default implementation."
1338+
keyworkDescriptionAnd,"Used in mutually recursive bindings, in property declarations, and with multiple constraints on generic parameters."
1339+
keywordDescriptionAs,"Used to give the current class object an object name. Also used to give a name to a whole pattern within a pattern match."
1340+
keywordDescriptionAssert,"Used to verify code during debugging."
1341+
keywordDescriptionBase,"Used as the name of the base class object."
1342+
keywordDescriptionBegin,""In verbose syntax, indicates the start of a code block."
1343+
keywordDescriptionClass,"In verbose syntax, indicates the start of a class definition."
1344+
keywordDescriptionDefault,"Indicates an implementation of an abstract method; used together with an abstract method declaration to create a virtual method."
1345+
keywordDescriptionDelegate,"Used to declare a delegate."
1346+
keywordDescriptionDo,"Used in looping constructs or to execute imperative code."
1347+
keywordDescriptionDone,"In verbose syntax, indicates the end of a block of code in a looping expression."
1348+
keywordDescriptionDowncast,"Used to convert to a type that is lower in the inheritance chain."
1349+
keywordDescriptionDownto,"In a for expression, used when counting in reverse."
1350+
keywordDescriptionElif,"Used in conditional branching. A short form of else if."
1351+
keywordDescriptionElse,"Used in conditional branching."
1352+
keywordDescriptionEnd,"In type definitions and type extensions, indicates the end of a section of member definitions. In verbose syntax, used to specify the end of a code block that starts with the begin keyword."
1353+
keywordDescriptionException,"Used to declare an exception type."
1354+
keywordDescriptionExtern,"Indicates that a declared program element is defined in another binary or assembly."
1355+
keywordDescriptionTrueFalse,"Used as a Boolean literal."
1356+
keywordDescriptionFinally,"Used together with try to introduce a block of code that executes regardless of whether an exception occurs."
1357+
keywordDescriptionFor,"Used in looping constructs."
1358+
keywordDescriptionFun,"Used in lambda expressions, also known as anonymous functions."
1359+
keywordDescriptionFunction,"Used as a shorter alternative to the fun keyword and a match expression in a lambda expression that has pattern matching on a single argument."
1360+
keywordDescriptionGlobal,"Used to reference the top-level .NET namespace."
1361+
keywordDescriptionIf,"Used in conditional branching constructs."
1362+
keywordDescriptionIn,"Used for sequence expressions and, in verbose syntax, to separate expressions from bindings."
1363+
keywordDescriptionInherit,"Used to specify a base class or base interface."
1364+
keywordDescriptionInline,"Used to indicate a function that should be integrated directly into the caller's code."
1365+
keywordDescriptionInterface,"Used to declare and implement interfaces."
1366+
keywordDescriptionInternal,"Used to specify that a member is visible inside an assembly but not outside it."
1367+
keywordDescriptionLazy,"Used to specify a computation that is to be performed only when a result is needed."
1368+
keywordDescriptionLet,"Used to associate, or bind, a name to a value or function."
1369+
keywordDescriptionLetBang,"Used in asynchronous workflows to bind a name to the result of an asynchronous computation, or, in other computation expressions, used to bind a name to a result, which is of the computation type."
1370+
keywordDescriptionMatch,"Used to branch by comparing a value to a pattern."
1371+
keywordDescriptionMember,"Used to declare a property or method in an object type."
1372+
keywordDescriptionModule,"Used to associate a name with a group of related types, values, and functions, to logically separate it from other code."
1373+
keywordDescriptionMutable,"Used to declare a variable, that is, a value that can be changed."
1374+
keywordDescriptionNamespace,"Used to associate a name with a group of related types and modules, to logically separate it from other code."
1375+
keywordDescriptionNew,"Used to declare, define, or invoke a constructor that creates or that can create an object. Also used in generic parameter constraints to indicate that a type must have a certain constructor."
1376+
keywordDescriptionNot,"Not actually a keyword. However, not struct in combination is used as a generic parameter constraint."
1377+
keywordDescriptionNull,"Indicates the absence of an object. Also used in generic parameter constraints."
1378+
keywordDescriptionOf,"Used in discriminated unions to indicate the type of categories of values, and in delegate and exception declarations."
1379+
keywordDescriptionOpen,"Used to make the contents of a namespace or module available without qualification."
1380+
keywordDescriptionOr,"Used with Boolean conditions as a Boolean or operator. Equivalent to ||. Also used in member constraints."
1381+
keywordDescriptionOverride,"Used to implement a version of an abstract or virtual method that differs from the base version."
1382+
keywordDescriptionPrivate,"Restricts access to a member to code in the same type or module."
1383+
keywordDescriptionPublic,"Allows access to a member from outside the type."
1384+
keywordDescriptionRec,"Used to indicate that a function is recursive."
1385+
keywordDescriptionReturn,"Used to indicate a value to provide as the result of a computation expression."
1386+
keywordDescriptionReturnBang,"Used to indicate a computation expression that, when evaluated, provides the result of the containing computation expression."
1387+
keywordDescriptionSelect,"Used in query expressions to specify what fields or columns to extract. Note that this is a contextual keyword, which means that it is not actually a reserved word and it only acts like a keyword in appropriate context."
1388+
keywordDescriptionStatic,"Used to indicate a method or property that can be called without an instance of a type, or a value member that is shared among all instances of a type."
1389+
keywordDescriptionStruct,"Used to declare a structure type. Also used in generic parameter constraints. Used for OCaml compatibility in module definitions."
1390+
keywordDescriptionThen,"Used in conditional expressions. Also used to perform side effects after object construction."
1391+
keywordDescriptionTo,"Used in for loops to indicate a range."
1392+
keywordDescriptionTry,"Used to introduce a block of code that might generate an exception. Used together with with or finally."
1393+
keywordDescriptionType,"Used to declare a class, record, structure, discriminated union, enumeration type, unit of measure, or type abbreviation."
1394+
keywordDescriptionUpcast,"Used to convert to a type that is higher in the inheritance chain."
1395+
keywordDescriptionUse,"Used instead of let for values that require Dispose to be called to free resources."
1396+
keywordDescriptionUseBang,"Used instead of let! in asynchronous workflows and other computation expressions for values that require Dispose to be called to free resources."
1397+
keywordDescriptionVal,"Used in a signature to indicate a value, or in a type to declare a member, in limited situations."
1398+
keywordDescriptionVoid,"Indicates the .NET void type. Used when interoperating with other .NET languages."
1399+
keywordDescriptionWhen,"Used for Boolean conditions (when guards) on pattern matches and to introduce a constraint clause for a generic type parameter."
1400+
keywordDescriptionWhile,"Introduces a looping construct."
1401+
keywordDescriptionWith,"Used together with the match keyword in pattern matching expressions. Also used in object expressions, record copying expressions, and type extensions to introduce member definitions, and to introduce exception handlers."
1402+
keywordDescriptionYield,"Used in a sequence expression to produce a value for a sequence."
1403+
keywordDescriptionYieldBang,"Used in a computation expression to append the result of a given computation expression to a collection of results for the containing computation expression."
1404+
keywordDescriptionRightArrow,"In function types, delimits arguments and return values. Yields an expression (in sequence expressions); equivalent to the yield keyword. Used in match expressions"
1405+
keywordDescriptionLeftArrow,"Assigns a value to a variable."
1406+
keywordDescriptionCast,"Converts a type to type that is higher in the hierarchy."
1407+
keywordDescriptionDynamicCast,"Converts a type to a type that is lower in the hierarchy."
1408+
keywordDescriptionTypedQuotation,"Delimits a typed code quotation."
1409+
keywordDescriptionUntypedQuotation,"Delimits a untyped code quotation."

‎src/fsharp/lexhelp.fs‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,82 @@ module Keywords =
355355
letNormalizeIdentifierBackticks(s:string):string=
356356
lets=if s.StartsWith"``"&& s.EndsWith"``"then s.[2..s.Length-3]else s
357357
QuoteIdentifierIfNeeded s
358+
359+
/// Keywords paired with their descriptions. Used in completion and quick info.
360+
letkeywordsWithDescription:(string* string)list=
361+
["abstract", FSComp.SR.keywordDescriptionAbstract()
362+
"and", FSComp.SR.keyworkDescriptionAnd()
363+
"as", FSComp.SR.keywordDescriptionAs()
364+
"assert", FSComp.SR.keywordDescriptionAssert()
365+
"base", FSComp.SR.keywordDescriptionBase()
366+
"begin", FSComp.SR.keywordDescriptionBegin()
367+
"class", FSComp.SR.keywordDescriptionClass()
368+
"default", FSComp.SR.keywordDescriptionDefault()
369+
"delegate", FSComp.SR.keywordDescriptionDelegate()
370+
"do", FSComp.SR.keywordDescriptionDo()
371+
"done", FSComp.SR.keywordDescriptionDone()
372+
"downcast", FSComp.SR.keywordDescriptionDowncast()
373+
"downto", FSComp.SR.keywordDescriptionDownto()
374+
"elif", FSComp.SR.keywordDescriptionElif()
375+
"else", FSComp.SR.keywordDescriptionElse()
376+
"end", FSComp.SR.keywordDescriptionEnd()
377+
"exception", FSComp.SR.keywordDescriptionException()
378+
"extern", FSComp.SR.keywordDescriptionExtern()
379+
"false", FSComp.SR.keywordDescriptionTrueFalse()
380+
"finally", FSComp.SR.keywordDescriptionFinally()
381+
"for", FSComp.SR.keywordDescriptionFor()
382+
"fun", FSComp.SR.keywordDescriptionFun()
383+
"function", FSComp.SR.keywordDescriptionFunction()
384+
"global", FSComp.SR.keywordDescriptionGlobal()
385+
"if", FSComp.SR.keywordDescriptionIf()
386+
"in", FSComp.SR.keywordDescriptionIn()
387+
"inherit", FSComp.SR.keywordDescriptionInherit()
388+
"inline", FSComp.SR.keywordDescriptionInline()
389+
"interface", FSComp.SR.keywordDescriptionInterface()
390+
"internal", FSComp.SR.keywordDescriptionInternal()
391+
"lazy", FSComp.SR.keywordDescriptionLazy()
392+
"let", FSComp.SR.keywordDescriptionLet()
393+
"let!", FSComp.SR.keywordDescriptionLetBang()
394+
"match", FSComp.SR.keywordDescriptionMatch()
395+
"member", FSComp.SR.keywordDescriptionMember()
396+
"module", FSComp.SR.keywordDescriptionModule()
397+
"mutable", FSComp.SR.keywordDescriptionMutable()
398+
"namespace", FSComp.SR.keywordDescriptionNamespace()
399+
"new", FSComp.SR.keywordDescriptionNew()
400+
"not", FSComp.SR.keywordDescriptionNot()
401+
"null", FSComp.SR.keywordDescriptionNull()
402+
"of", FSComp.SR.keywordDescriptionOf()
403+
"open", FSComp.SR.keywordDescriptionOpen()
404+
"or", FSComp.SR.keywordDescriptionOr()
405+
"override", FSComp.SR.keywordDescriptionOverride()
406+
"private", FSComp.SR.keywordDescriptionPrivate()
407+
"public", FSComp.SR.keywordDescriptionPublic()
408+
"rec", FSComp.SR.keywordDescriptionRec()
409+
"return", FSComp.SR.keywordDescriptionReturn()
410+
"return!", FSComp.SR.keywordDescriptionReturnBang()
411+
"select", FSComp.SR.keywordDescriptionSelect()
412+
"static", FSComp.SR.keywordDescriptionStatic()
413+
"struct", FSComp.SR.keywordDescriptionStruct()
414+
"then", FSComp.SR.keywordDescriptionThen()
415+
"to", FSComp.SR.keywordDescriptionTo()
416+
"true", FSComp.SR.keywordDescriptionTrueFalse()
417+
"try", FSComp.SR.keywordDescriptionTry()
418+
"type", FSComp.SR.keywordDescriptionType()
419+
"upcast", FSComp.SR.keywordDescriptionUpcast()
420+
"use", FSComp.SR.keywordDescriptionUse()
421+
"use!", FSComp.SR.keywordDescriptionUseBang()
422+
"val", FSComp.SR.keywordDescriptionVal()
423+
"void", FSComp.SR.keywordDescriptionVoid()
424+
"when", FSComp.SR.keywordDescriptionWhen()
425+
"while", FSComp.SR.keywordDescriptionWhile()
426+
"with", FSComp.SR.keywordDescriptionWith()
427+
"yield", FSComp.SR.keywordDescriptionYield()
428+
"yield!", FSComp.SR.keywordDescriptionYieldBang()
429+
"->", FSComp.SR.keywordDescriptionRightArrow()
430+
"<-", FSComp.SR.keywordDescriptionLeftArrow()
431+
":>", FSComp.SR.keywordDescriptionCast()
432+
":?>", FSComp.SR.keywordDescriptionDynamicCast()
433+
"<@", FSComp.SR.keywordDescriptionTypedQuotation()
434+
"@>", FSComp.SR.keywordDescriptionTypedQuotation()
435+
"<@@", FSComp.SR.keywordDescriptionUntypedQuotation()
436+
"@@>", FSComp.SR.keywordDescriptionUntypedQuotation()]

‎src/fsharp/lexhelp.fsi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ module Keywords =
7171
valNormalizeIdentifierBackticks:string->string
7272
valkeywordNames:string list
7373
valkeywordTypes:Set<string>
74+
/// Keywords paired with their descriptions. Used in completion and quick info.
75+
valkeywordsWithDescription:(string* string)list

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

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ namespace Microsoft.VisualStudio.FSharp.Editor
44

55
openSystem
66
openSystem.Composition
7-
openSystem.Collections.Concurrent
87
openSystem.Collections.Generic
98
openSystem.Collections.Immutable
109
openSystem.Threading
1110
openSystem.Threading.Tasks
12-
openSystem.Linq
1311
openSystem.Runtime.CompilerServices
1412

1513
openMicrosoft.CodeAnalysis
1614
openMicrosoft.CodeAnalysis.Completion
1715
openMicrosoft.CodeAnalysis.Classification
1816
openMicrosoft.CodeAnalysis.Editor
19-
openMicrosoft.CodeAnalysis.Editor.Implementation.Debugging
20-
openMicrosoft.CodeAnalysis.Editor.Shared.Utilities
21-
openMicrosoft.CodeAnalysis.Formatting
2217
openMicrosoft.CodeAnalysis.Host
2318
openMicrosoft.CodeAnalysis.Host.Mef
2419
openMicrosoft.CodeAnalysis.Options
@@ -177,35 +172,4 @@ type internal FSharpCompletionProvider
177172
|true, x-> x
178173
|_-> item.DisplayText
179174

180-
Task.FromResult(CompletionChange.Create(new TextChange(item.Span, nameInCode)))
181-
182-
typeinternalFSharpCompletionService
183-
(
184-
workspace: Workspace,
185-
serviceProvider: SVsServiceProvider,
186-
checkerProvider: FSharpCheckerProvider,
187-
projectInfoManager: ProjectInfoManager
188-
)=
189-
inherit CompletionServiceWithProviders(workspace)
190-
191-
letbuiltInProviders= ImmutableArray.Create<CompletionProvider>(FSharpCompletionProvider(workspace, serviceProvider, checkerProvider, projectInfoManager))
192-
letcompletionRules= CompletionRules.Default.WithDismissIfEmpty(true).WithDismissIfLastCharacterDeleted(true).WithDefaultEnterKeyRule(EnterKeyRule.Never)
193-
194-
overridethis.Language= FSharpCommonConstants.FSharpLanguageName
195-
overridethis.GetBuiltInProviders()= builtInProviders
196-
overridethis.GetRules()= completionRules
197-
198-
[<Shared>]
199-
[<ExportLanguageServiceFactory(typeof<CompletionService>, FSharpCommonConstants.FSharpLanguageName)>]
200-
typeinternalFSharpCompletionServiceFactory
201-
[<ImportingConstructor>]
202-
(
203-
serviceProvider: SVsServiceProvider,
204-
checkerProvider: FSharpCheckerProvider,
205-
projectInfoManager: ProjectInfoManager
206-
)=
207-
interface ILanguageServiceFactorywith
208-
memberthis.CreateLanguageService(hostLanguageServices:HostLanguageServices):ILanguageService=
209-
upcastnew FSharpCompletionService(hostLanguageServices.WorkspaceServices.Workspace, serviceProvider, checkerProvider, projectInfoManager)
210-
211-
175+
Task.FromResult(CompletionChange.Create(new TextChange(item.Span, nameInCode)))
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.Composition
7+
openSystem.Collections.Concurrent
8+
openSystem.Collections.Generic
9+
openSystem.Collections.Immutable
10+
openSystem.Threading
11+
openSystem.Threading.Tasks
12+
openSystem.Linq
13+
openSystem.Runtime.CompilerServices
14+
15+
openMicrosoft.CodeAnalysis
16+
openMicrosoft.CodeAnalysis.Completion
17+
openMicrosoft.CodeAnalysis.Host
18+
openMicrosoft.CodeAnalysis.Host.Mef
19+
20+
openMicrosoft.VisualStudio.Shell
21+
22+
typeinternalFSharpCompletionService
23+
(
24+
workspace: Workspace,
25+
serviceProvider: SVsServiceProvider,
26+
checkerProvider: FSharpCheckerProvider,
27+
projectInfoManager: ProjectInfoManager
28+
)=
29+
inherit CompletionServiceWithProviders(workspace)
30+
31+
letbuiltInProviders=
32+
ImmutableArray.Create<CompletionProvider>(
33+
FSharpCompletionProvider(workspace, serviceProvider, checkerProvider, projectInfoManager),
34+
FSharpKeywordCompletionProvider(workspace, projectInfoManager))
35+
36+
letcompletionRules=
37+
CompletionRules.Default
38+
.WithDismissIfEmpty(true)
39+
.WithDismissIfLastCharacterDeleted(true)
40+
.WithDefaultEnterKeyRule(EnterKeyRule.Never)
41+
42+
overridethis.Language= FSharpCommonConstants.FSharpLanguageName
43+
overridethis.GetBuiltInProviders()= builtInProviders
44+
overridethis.GetRules()= completionRules
45+
46+
[<Shared>]
47+
[<ExportLanguageServiceFactory(typeof<CompletionService>, FSharpCommonConstants.FSharpLanguageName)>]
48+
typeinternalFSharpCompletionServiceFactory
49+
[<ImportingConstructor>]
50+
(
51+
serviceProvider: SVsServiceProvider,
52+
checkerProvider: FSharpCheckerProvider,
53+
projectInfoManager: ProjectInfoManager
54+
)=
55+
interface ILanguageServiceFactorywith
56+
memberthis.CreateLanguageService(hostLanguageServices:HostLanguageServices):ILanguageService=
57+
upcastnew FSharpCompletionService(hostLanguageServices.WorkspaceServices.Workspace, serviceProvider, checkerProvider, projectInfoManager)
58+
59+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp