Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/protocol/LSP.Completion.pas
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ TCompletionItem = class(TCollectionItem)
constructor Create(ACollection: TCollection); override;
destructor destroy; override;
public
// the following private fields are for private us and not part of LSP
overloadCount: integer;
procedure SetAdditionalTextEdits(AValue: TTextEdits);
procedure SetCommitCharacters(AValue: TStrings);
procedure SetDocumentation(AValue: TMarkupContent);
Expand Down
2 changes: 1 addition & 1 deletion src/serverprotocol/PasLS.ApplyEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ procedure DoApplyEdit(aTransport: TMessageTransport; DocumentURI, Text: String;
// but ideally you're supposed to provided correct versions.
// See `OptionalVersionedTextDocumentIdentifier` from
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#versionedTextDocumentIdentifier
if ServerSettings.nullDocumentVersion then
if ClientInfo.name = TClients.SublimeTextLSP then
TextDocumentEdit.textDocument.version := nil
else
TextDocumentEdit.textDocument.version := 0;
Expand Down
94 changes: 22 additions & 72 deletions src/serverprotocol/PasLS.Completion.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,50 +37,23 @@ TCompletion = class(specialize TLSPRequest<TCompletionParams, TCompletionList>
function Process(var Params: TCompletionParams): TCompletionList; override;
end;

{ TCompletionItemHelper }

type
TCompletionItemHelper = class helper for TCompletionItem
private
procedure SetPrimaryText(text: string);
procedure SetSecondaryText(text: string);
public
property primaryText: string write SetPrimaryText;
property secondaryText: string write SetSecondaryText;
end;



implementation

uses
SysUtils, Contnrs,
PasLS.CodeUtils, PasLS.Diagnostics, PasLS.Settings;

procedure TCompletionItemHelper.SetPrimaryText(text: string);
begin
filterText := text;
if not ServerSettings.filterTextOnly then
&label := text;
end;

procedure TCompletionItemHelper.SetSecondaryText(text: string);
begin
if not ServerSettings.filterTextOnly then
&label := text;
end;


{ TCompletion }

function TCompletion.KindForIdentifier(Identifier: TIdentifierListItem): TCompletionItemKind;
var desc:TCodeTreeNodeDesc;
var
desc: TCodeTreeNodeDesc;
begin

// PredefinedIdentifiers no node ,use default desc
if Identifier.Node = nil then
desc:=Identifier.DefaultDesc
desc := Identifier.DefaultDesc
else
desc:= Identifier.Node.Desc;
desc := Identifier.Node.Desc;

// get completion item kind from identifier node
case desc of
Expand Down Expand Up @@ -143,16 +116,12 @@ function TCompletion.KindForIdentifier(Identifier: TIdentifierListItem): TComple
ctnEnumIdentifier:
result := TCompletionItemKind.EnumMemberItem;
otherwise
// Transport.SendDiagnostic('Default kind for %s (%s)', [Identifier.Identifier, Identifier.Node.DescAsString]);
//PrintIdentifierTree(Identifier);
result := TCompletionItemKind.KeywordItem;
end;
end;


function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
var

Code: TCodeBuffer;
X, Y, PStart, PEnd, Count, I: Integer;
Line: String;
Expand All @@ -176,7 +145,6 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
exit;
end;


X := position.character;
Y := position.line;
Line := Code.GetLine(Y);
Expand All @@ -193,11 +161,10 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
if CodeToolBoss.GatherIdentifiers(Code, X + 1, Y + 1) then
begin
Count := CodeToolBoss.IdentifierList.GetFilteredCount;
IdentContext := '';
IdentDetails := '';

for I := 0 to Count - 1 do
begin

// make sure we don't exceed the maximum completions count
if (ServerSettings.maximumCompletions > -1) and (I >= ServerSettings.maximumCompletions) then
begin
Expand All @@ -212,38 +179,29 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList;

if Identifier.IsProcNodeWithParams then
begin
//SnippetText := ParseParamList(RawList, True);
//SnippetText := '$0';

// the completion is overloaded so increment the overload count
// Ignore duplicate overloads
Completion := TCompletionItem(OverloadMap.Find(Identifier.Identifier));
if Completion <> nil then
begin
Inc(Completion.overloadCount);
if Completion.overloadCount = 1 then
Completion.secondaryText := '+'+IntToStr(Completion.overloadCount)+' overload'
else
Completion.secondaryText := '+'+IntToStr(Completion.overloadCount)+' overloads';
continue;
end;
continue;

Kind := KindForIdentifier(Identifier);

if (ServerSettings.ignoreTextCompletions) and (Kind = TCompletionItemKind.TextItem) then
continue;

Completion := Completions.Add;
Completion.primaryText := Identifier.Identifier;
Completion.secondaryText := IdentContext;
Completion.&label := Identifier.Identifier;
Completion.kind := Kind;

if not ServerSettings.minimalisticCompletions then
begin
// todo: make showing parameters in details as an option?
//Completion.detail := IdentDetails+' ('+Identifier.ParamNameList+')';
// TODO: in 3.17 implement labelDetails to show parameters
// then we can consider showing overloads in the list
Completion.detail := IdentDetails;

if ServerSettings.insertCompletionsAsSnippets then
begin
// TODO: use `ParseParamList(AsSnippet)` instead of $0
Completion.insertText := Identifier.Identifier+'($0)';
Completion.insertTextFormat := TInsertTextFormat.Snippet;
end
Expand All @@ -265,27 +223,19 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList;
continue;

Completion := Completions.Add;
Completion.&label := Identifier.Identifier;
if not ServerSettings.minimalisticCompletions then
begin
Completion.secondaryText := IdentContext;
Completion.primaryText := Identifier.Identifier;
Completion.detail := IdentDetails;
Completion.insertText := Identifier.Identifier;
Completion.insertTextFormat := TInsertTextFormat.PlainText;
end
else
begin
Completion.primaryText := Identifier.Identifier;
Completion.secondaryText := Identifier.Identifier;
end;
Completion.detail := IdentDetails;
Completion.kind := Kind;
Completion.sortText := IntToStr(I);
end;
end;
end else begin
PublishCodeToolsError(Self.Transport,'');
Result.isIncomplete := true;
end;
end
else
begin
PublishCodeToolsError(Self.Transport,'');
Result.isIncomplete := true;
end;
except
on E: Exception do
begin
Expand Down
4 changes: 1 addition & 3 deletions src/serverprotocol/PasLS.General.pas
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ procedure TInitialize.CollectWorkSpacePaths(WorkspaceFolders: TWorkspaceFolderIt
procedure TInitialize.ShowConfigStatus(Params: TInitializeParams; CodeToolsOptions: TCodeToolsOptions);
var
ExcludeList, Option: String;
FPCOptions: TStringArray;
I: Integer;
FPCOptions: TStringArray;
begin
DoLog(kStatusPrefix+'Server: ' + {$INCLUDE %DATE%});
DoLog(kStatusPrefix+'Client: ' + Params.clientInfo.name + ' ' + Params.clientInfo.version);
Expand Down Expand Up @@ -302,8 +302,6 @@ procedure TInitialize.ShowConfigStatus(Params: TInitializeParams; CodeToolsOptio
DoLog(kSettingPrefix+'minimalisticCompletions: ', ServerSettings.minimalisticCompletions);
DoLog(kSettingPrefix+'showSyntaxErrors: ', ServerSettings.showSyntaxErrors);
DoLog(kSettingPrefix+'flatSymbolMode: ', ServerSettings.flatSymbolMode);
DoLog(kSettingPrefix+'nullDocumentVersion: ', ServerSettings.nullDocumentVersion);
DoLog(kSettingPrefix+'filterTextOnly: ', ServerSettings.filterTextOnly);

// Show excludeSymbols
if ServerSettings.excludeSymbols.Count > 0 then
Expand Down
6 changes: 0 additions & 6 deletions src/serverprotocol/PasLS.Settings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ TServerSettings = class(TInitializationOptions)
property checkInactiveRegions : Boolean read fBooleans[11] write fBooleans[11];
// Force flat symbol mode (SymbolInformation[]) instead of hierarchical
property flatSymbolMode: Boolean read fBooleans[12] write fBooleans[12];
// Use nil instead of 0 for document version in workspace edits
property nullDocumentVersion: Boolean read fBooleans[13] write fBooleans[13];
// Only set filterText in completion items, not label
property filterTextOnly: Boolean read fBooleans[14] write fBooleans[14];
// Array of symbol types to exclude from document symbols
property excludeSymbols: TStrings read fExcludeSymbols write SetExcludeSymbols;
public
Expand Down Expand Up @@ -386,8 +382,6 @@ class function TServerSettings.GetPropertyDescription(const PropName: String): S
'scanFilePatterns': Result := 'File patterns for workspace scanning (array of glob patterns, e.g. ["*.pas", "*.pp"])';
'checkInactiveRegions': Result := 'Check inactive regions';
'flatSymbolMode': Result := 'Force flat symbol mode (SymbolInformation[]) instead of hierarchical';
'nullDocumentVersion': Result := 'Use nil instead of 0 for document version in workspace edits';
'filterTextOnly': Result := 'Only set filterText in completion items, not label';
'excludeSymbols': Result := 'Array of symbol types to exclude: sectionContainers, interfaceMethodDecls, implClassDefs, fields, properties, constants, enumMembers';
else
Result := '';
Expand Down
4 changes: 0 additions & 4 deletions src/tests/Tests.SublimeProfile.pas
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ procedure SetupSublimeProfile;
begin
// Sublime Text LSP profile settings
ServerSettings.flatSymbolMode := True;
ServerSettings.nullDocumentVersion := True;
ServerSettings.filterTextOnly := True;
ServerSettings.excludeSymbols.Clear;
ServerSettings.excludeSymbols.Add('sectionContainers');
ServerSettings.excludeSymbols.Add('interfaceMethodDecls');
Expand All @@ -168,8 +166,6 @@ procedure ResetToDefaultProfile;
begin
// Default profile settings (show everything)
ServerSettings.flatSymbolMode := False;
ServerSettings.nullDocumentVersion := False;
ServerSettings.filterTextOnly := False;
ServerSettings.excludeSymbols.Clear;
// Trigger set to update the exclusion set
ServerSettings.excludeSymbols := ServerSettings.excludeSymbols;
Expand Down