Skip to content

Commit 25a2348

Browse files
authored
Merge pull request #145 from genericptr/remove-completion-overloads
Remove completion overloads
2 parents 3724409 + 8190a37 commit 25a2348

6 files changed

Lines changed: 24 additions & 88 deletions

File tree

src/protocol/LSP.Completion.pas

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ TCompletionItem = class(TCollectionItem)
166166
constructor Create(ACollection: TCollection); override;
167167
destructor destroy; override;
168168
public
169-
// the following private fields are for private us and not part of LSP
170-
overloadCount: integer;
171169
procedure SetAdditionalTextEdits(AValue: TTextEdits);
172170
procedure SetCommitCharacters(AValue: TStrings);
173171
procedure SetDocumentation(AValue: TMarkupContent);

src/serverprotocol/PasLS.ApplyEdit.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ procedure DoApplyEdit(aTransport: TMessageTransport; DocumentURI, Text: String;
5858
// but ideally you're supposed to provided correct versions.
5959
// See `OptionalVersionedTextDocumentIdentifier` from
6060
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#versionedTextDocumentIdentifier
61-
if ServerSettings.nullDocumentVersion then
61+
if ClientInfo.name = TClients.SublimeTextLSP then
6262
TextDocumentEdit.textDocument.version := nil
6363
else
6464
TextDocumentEdit.textDocument.version := 0;

src/serverprotocol/PasLS.Completion.pas

Lines changed: 22 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
5440
implementation
5541

5642
uses
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+
7548
function TCompletion.KindForIdentifier(Identifier: TIdentifierListItem): TCompletionItemKind;
76-
var desc:TCodeTreeNodeDesc;
49+
var
50+
desc: TCodeTreeNodeDesc;
7751
begin
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;
150121
end;
151122

152-
153123
function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
154124
var
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

src/serverprotocol/PasLS.General.pas

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ procedure TInitialize.CollectWorkSpacePaths(WorkspaceFolders: TWorkspaceFolderIt
248248
procedure TInitialize.ShowConfigStatus(Params: TInitializeParams; CodeToolsOptions: TCodeToolsOptions);
249249
var
250250
ExcludeList, Option: String;
251-
FPCOptions: TStringArray;
252251
I: Integer;
252+
FPCOptions: TStringArray;
253253
begin
254254
DoLog(kStatusPrefix+'Server: ' + {$INCLUDE %DATE%});
255255
DoLog(kStatusPrefix+'Client: ' + Params.clientInfo.name + ' ' + Params.clientInfo.version);
@@ -302,8 +302,6 @@ procedure TInitialize.ShowConfigStatus(Params: TInitializeParams; CodeToolsOptio
302302
DoLog(kSettingPrefix+'minimalisticCompletions: ', ServerSettings.minimalisticCompletions);
303303
DoLog(kSettingPrefix+'showSyntaxErrors: ', ServerSettings.showSyntaxErrors);
304304
DoLog(kSettingPrefix+'flatSymbolMode: ', ServerSettings.flatSymbolMode);
305-
DoLog(kSettingPrefix+'nullDocumentVersion: ', ServerSettings.nullDocumentVersion);
306-
DoLog(kSettingPrefix+'filterTextOnly: ', ServerSettings.filterTextOnly);
307305

308306
// Show excludeSymbols
309307
if ServerSettings.excludeSymbols.Count > 0 then

src/serverprotocol/PasLS.Settings.pas

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ TServerSettings = class(TInitializationOptions)
142142
property checkInactiveRegions : Boolean read fBooleans[11] write fBooleans[11];
143143
// Force flat symbol mode (SymbolInformation[]) instead of hierarchical
144144
property flatSymbolMode: Boolean read fBooleans[12] write fBooleans[12];
145-
// Use nil instead of 0 for document version in workspace edits
146-
property nullDocumentVersion: Boolean read fBooleans[13] write fBooleans[13];
147-
// Only set filterText in completion items, not label
148-
property filterTextOnly: Boolean read fBooleans[14] write fBooleans[14];
149145
// Array of symbol types to exclude from document symbols
150146
property excludeSymbols: TStrings read fExcludeSymbols write SetExcludeSymbols;
151147
public
@@ -386,8 +382,6 @@ class function TServerSettings.GetPropertyDescription(const PropName: String): S
386382
'scanFilePatterns': Result := 'File patterns for workspace scanning (array of glob patterns, e.g. ["*.pas", "*.pp"])';
387383
'checkInactiveRegions': Result := 'Check inactive regions';
388384
'flatSymbolMode': Result := 'Force flat symbol mode (SymbolInformation[]) instead of hierarchical';
389-
'nullDocumentVersion': Result := 'Use nil instead of 0 for document version in workspace edits';
390-
'filterTextOnly': Result := 'Only set filterText in completion items, not label';
391385
'excludeSymbols': Result := 'Array of symbol types to exclude: sectionContainers, interfaceMethodDecls, implClassDefs, fields, properties, constants, enumMembers';
392386
else
393387
Result := '';

src/tests/Tests.SublimeProfile.pas

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ procedure SetupSublimeProfile;
154154
begin
155155
// Sublime Text LSP profile settings
156156
ServerSettings.flatSymbolMode := True;
157-
ServerSettings.nullDocumentVersion := True;
158-
ServerSettings.filterTextOnly := True;
159157
ServerSettings.excludeSymbols.Clear;
160158
ServerSettings.excludeSymbols.Add('sectionContainers');
161159
ServerSettings.excludeSymbols.Add('interfaceMethodDecls');
@@ -168,8 +166,6 @@ procedure ResetToDefaultProfile;
168166
begin
169167
// Default profile settings (show everything)
170168
ServerSettings.flatSymbolMode := False;
171-
ServerSettings.nullDocumentVersion := False;
172-
ServerSettings.filterTextOnly := False;
173169
ServerSettings.excludeSymbols.Clear;
174170
// Trigger set to update the exclusion set
175171
ServerSettings.excludeSymbols := ServerSettings.excludeSymbols;

0 commit comments

Comments
 (0)