@@ -37,50 +37,23 @@ TCompletion = class(specialize TLSPRequest<TCompletionParams, TCompletionList>
3737 function Process (var Params: TCompletionParams): TCompletionList; override;
3838 end ;
3939
40- { TCompletionItemHelper }
41-
42- type
43- TCompletionItemHelper = class helper for TCompletionItem
44- private
45- procedure SetPrimaryText (text: string);
46- procedure SetSecondaryText (text: string);
47- public
48- property primaryText: string write SetPrimaryText;
49- property secondaryText: string write SetSecondaryText;
50- end ;
51-
52-
53-
5440implementation
5541
5642uses
5743 SysUtils, Contnrs,
5844 PasLS.CodeUtils, PasLS.Diagnostics, PasLS.Settings;
5945
60- procedure TCompletionItemHelper.SetPrimaryText (text: string);
61- begin
62- filterText := text;
63- if not ServerSettings.filterTextOnly then
64- &label := text;
65- end ;
66-
67- procedure TCompletionItemHelper.SetSecondaryText (text: string);
68- begin
69- if not ServerSettings.filterTextOnly then
70- &label := text;
71- end ;
72-
73-
7446{ TCompletion }
47+
7548function TCompletion.KindForIdentifier (Identifier: TIdentifierListItem): TCompletionItemKind;
76- var desc:TCodeTreeNodeDesc;
49+ var
50+ desc: TCodeTreeNodeDesc;
7751begin
78-
7952 // PredefinedIdentifiers no node ,use default desc
8053 if Identifier.Node = nil then
81- desc:= Identifier.DefaultDesc
54+ desc := Identifier.DefaultDesc
8255 else
83- desc:= Identifier.Node.Desc;
56+ desc := Identifier.Node.Desc;
8457
8558 // get completion item kind from identifier node
8659 case desc of
@@ -143,16 +116,12 @@ function TCompletion.KindForIdentifier(Identifier: TIdentifierListItem): TComple
143116 ctnEnumIdentifier:
144117 result := TCompletionItemKind.EnumMemberItem;
145118 otherwise
146- // Transport.SendDiagnostic('Default kind for %s (%s)', [Identifier.Identifier, Identifier.Node.DescAsString]);
147- // PrintIdentifierTree(Identifier);
148119 result := TCompletionItemKind.KeywordItem;
149120 end ;
150121end ;
151122
152-
153123function TCompletion.Process (var Params: TCompletionParams): TCompletionList;
154124var
155-
156125 Code: TCodeBuffer;
157126 X, Y, PStart, PEnd, Count, I: Integer;
158127 Line: String;
@@ -176,7 +145,6 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
176145 exit;
177146 end ;
178147
179-
180148 X := position.character;
181149 Y := position.line;
182150 Line := Code.GetLine(Y);
@@ -193,11 +161,10 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
193161 if CodeToolBoss.GatherIdentifiers(Code, X + 1 , Y + 1 ) then
194162 begin
195163 Count := CodeToolBoss.IdentifierList.GetFilteredCount;
196- IdentContext := ' ' ;
197164 IdentDetails := ' ' ;
165+
198166 for I := 0 to Count - 1 do
199167 begin
200-
201168 // make sure we don't exceed the maximum completions count
202169 if (ServerSettings.maximumCompletions > -1 ) and (I >= ServerSettings.maximumCompletions) then
203170 begin
@@ -212,38 +179,29 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
212179
213180 if Identifier.IsProcNodeWithParams then
214181 begin
215- // SnippetText := ParseParamList(RawList, True);
216- // SnippetText := '$0';
217-
218- // the completion is overloaded so increment the overload count
182+ // Ignore duplicate overloads
219183 Completion := TCompletionItem(OverloadMap.Find(Identifier.Identifier));
220184 if Completion <> nil then
221- begin
222- Inc(Completion.overloadCount);
223- if Completion.overloadCount = 1 then
224- Completion.secondaryText := ' +' +IntToStr(Completion.overloadCount)+' overload'
225- else
226- Completion.secondaryText := ' +' +IntToStr(Completion.overloadCount)+' overloads' ;
227- continue;
228- end ;
185+ continue;
229186
230187 Kind := KindForIdentifier(Identifier);
231188
232189 if (ServerSettings.ignoreTextCompletions) and (Kind = TCompletionItemKind.TextItem) then
233190 continue;
234191
235192 Completion := Completions.Add;
236- Completion.primaryText := Identifier.Identifier;
237- Completion.secondaryText := IdentContext;
193+ Completion.&label := Identifier.Identifier;
238194 Completion.kind := Kind;
239-
195+
240196 if not ServerSettings.minimalisticCompletions then
241197 begin
242- // todo: make showing parameters in details as an option?
243- // Completion.detail := IdentDetails+' ('+Identifier.ParamNameList+')';
198+ // TODO: in 3.17 implement labelDetails to show parameters
199+ // then we can consider showing overloads in the list
244200 Completion.detail := IdentDetails;
201+
245202 if ServerSettings.insertCompletionsAsSnippets then
246203 begin
204+ // TODO: use `ParseParamList(AsSnippet)` instead of $0
247205 Completion.insertText := Identifier.Identifier+' ($0)' ;
248206 Completion.insertTextFormat := TInsertTextFormat.Snippet;
249207 end
@@ -265,27 +223,19 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
265223 continue;
266224
267225 Completion := Completions.Add;
226+ Completion.&label := Identifier.Identifier;
268227 if not ServerSettings.minimalisticCompletions then
269- begin
270- Completion.secondaryText := IdentContext;
271- Completion.primaryText := Identifier.Identifier;
272- Completion.detail := IdentDetails;
273- Completion.insertText := Identifier.Identifier;
274- Completion.insertTextFormat := TInsertTextFormat.PlainText;
275- end
276- else
277- begin
278- Completion.primaryText := Identifier.Identifier;
279- Completion.secondaryText := Identifier.Identifier;
280- end ;
228+ Completion.detail := IdentDetails;
281229 Completion.kind := Kind;
282230 Completion.sortText := IntToStr(I);
283231 end ;
284232 end ;
285- end else begin
286- PublishCodeToolsError(Self.Transport,' ' );
287- Result.isIncomplete := true;
288- end ;
233+ end
234+ else
235+ begin
236+ PublishCodeToolsError(Self.Transport,' ' );
237+ Result.isIncomplete := true;
238+ end ;
289239 except
290240 on E: Exception do
291241 begin
0 commit comments