diff --git a/src/protocol/LSP.Completion.pas b/src/protocol/LSP.Completion.pas index f021a32..6f76c83 100644 --- a/src/protocol/LSP.Completion.pas +++ b/src/protocol/LSP.Completion.pas @@ -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); diff --git a/src/serverprotocol/PasLS.ApplyEdit.pas b/src/serverprotocol/PasLS.ApplyEdit.pas index e89c1d1..b88bb59 100644 --- a/src/serverprotocol/PasLS.ApplyEdit.pas +++ b/src/serverprotocol/PasLS.ApplyEdit.pas @@ -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; diff --git a/src/serverprotocol/PasLS.Completion.pas b/src/serverprotocol/PasLS.Completion.pas index 5e25190..2cc56a7 100644 --- a/src/serverprotocol/PasLS.Completion.pas +++ b/src/serverprotocol/PasLS.Completion.pas @@ -37,50 +37,23 @@ TCompletion = class(specialize TLSPRequest 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 @@ -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; @@ -176,7 +145,6 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList; exit; end; - X := position.character; Y := position.line; Line := Code.GetLine(Y); @@ -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 @@ -212,20 +179,10 @@ 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); @@ -233,17 +190,18 @@ function TCompletion.Process(var Params: TCompletionParams): TCompletionList; 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 @@ -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 diff --git a/src/serverprotocol/PasLS.General.pas b/src/serverprotocol/PasLS.General.pas index ad2269a..305e276 100644 --- a/src/serverprotocol/PasLS.General.pas +++ b/src/serverprotocol/PasLS.General.pas @@ -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); @@ -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 diff --git a/src/serverprotocol/PasLS.Settings.pas b/src/serverprotocol/PasLS.Settings.pas index fb0a8bc..1e0c0df 100644 --- a/src/serverprotocol/PasLS.Settings.pas +++ b/src/serverprotocol/PasLS.Settings.pas @@ -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 @@ -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 := ''; diff --git a/src/tests/Tests.SublimeProfile.pas b/src/tests/Tests.SublimeProfile.pas index 8d5b3a8..a712375 100644 --- a/src/tests/Tests.SublimeProfile.pas +++ b/src/tests/Tests.SublimeProfile.pas @@ -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'); @@ -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;