Skip to content

Commit 6fde4cd

Browse files
committed
Support castle-pasls-paths.txt to easier add paths
1 parent d698768 commit 6fde4cd

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ CGE fork contributes back improvements that are not CGE-specific (see e.g. https
2424
- Provide custom Lazarus config location (useful if you install Lazarus by [fpcupdeluxe](https://castle-engine.io/fpcupdeluxe) but still want `pasls` to read Lazarus config -- this is optional).
2525
- Improve debugging by known log filename and more complete JSON logs.
2626

27+
- We add capability to configure the LSP server using `castle-pasls-paths.txt`, see below.
28+
2729
- We can also auto-detect _Castle Game Engine_ path in some situations:
2830
- If the LSP server binary is distributed in `bin` of _Castle Game Engine_.
2931
- Or if the environment 'CASTLE_ENGINE_PATH` is defined.
@@ -144,7 +146,7 @@ Additional keys in LSP initialization options can be used to influence the LSP s
144146

145147
- 2: Return an error to the LSP client. Some LSP clients will just hide the error, but some (like Emacs) will show it clearly and prominently.
146148

147-
## Extra configuration in castle-engine/pascal-language-server
149+
## Extra configuration in castle-engine/pascal-language-server (castle-pasls.ini)
148150

149151
The `pasls` reads configuration file `castle-pasls.ini` in user config dir to enable some additional features.
150152

@@ -194,6 +196,24 @@ option_2=-dSOME_DEFINE
194196
option_3=-dSOMETHING_MORE
195197
```
196198

199+
## Extra paths from `castle-pasls-paths.txt`
200+
201+
We also read `castle-pasls-paths.txt` file in the same directory as `castle-pasls.ini`.
202+
203+
The format of this is simpler: any line that is not empty and does not start with `#` (comment) is considered a path to add to FPC search paths. It is added as both units and include paths (causes both `-Fu` and `-Fi` for FPC).
204+
205+
This is useful e.g. to add paths to all your custom units, that you want to be available for autocompletion. It would be also possible to do this by extending `[extra_options]` in `castle-pasls.ini`, but that's sometimes too bothersome: you need to add them twice (if you want both `-Fu` and `-Fi`) and you need to remember to keep order of `option_xxx`.
206+
207+
Example:
208+
209+
```
210+
# This is a comment, ignored.
211+
# Add all my custom units.
212+
/home/michalis/sources/my-units/
213+
/home/michalis/sources/more-units-and-include-files/
214+
/home/michalis/sources/more-units-and-include-files/subdirectory/
215+
```
216+
197217
## Roadmap
198218

199219
### Wishlist

server/castlelsp.pas

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
Copyright 2022-2024 Michalis Kamburelis
2+
Copyright 2022-2025 Michalis Kamburelis
33
44
Extensions to the Pascal Language Server specific to Castle Game Engine.
55
See https://github.com/michaliskambi/elisp/tree/master/lsp
@@ -26,10 +26,11 @@ interface
2626
uses Classes, IniFiles;
2727

2828
var
29-
UserConfig: TIniFile;
30-
WorkspacePaths: TStringList; // paths to search by workspace symbols
31-
WorkspaceAndEnginePaths: TStringList; // paths to search by workspace symbols in engine developer mode
32-
EngineDeveloperMode: Boolean; // add engine paths to workspace symbols?
29+
UserConfig: TIniFile; //< for reading ~/.config/pasls/castle-pasls.ini
30+
UserConfigPaths: TStringList; //< for reading ~/.config/pasls/castle-pasls-paths.txt
31+
WorkspacePaths: TStringList; //< paths to search by workspace symbols
32+
WorkspaceAndEnginePaths: TStringList; //< paths to search by workspace symbols in engine developer mode
33+
EngineDeveloperMode: Boolean; //< add engine paths to workspace symbols?
3334

3435
procedure InitializeUserConfig;
3536

@@ -39,6 +40,7 @@ procedure InitializeUserConfig;
3940
- extra CGE paths (derived from the single CGE path from castle-pasls.ini file)
4041
- extra CGE options (like -Mobjfpc)
4142
- extra free FPC options from castle-pasls.ini file
43+
- extra paths from castle-pasls-paths.txt
4244
}
4345
function ExtraFpcOptions: String;
4446

@@ -59,24 +61,33 @@ implementation
5961

6062
procedure InitializeUserConfig;
6163
var
62-
FileName: String;
64+
ConfigFileName, PathsFileName: String;
6365
begin
6466
{$ifdef UNIX_WITH_USERS_UNIT}
6567
{ Special hack for Unix + VSCode integration in https://github.com/genericptr/pasls-vscode ,
6668
looks like it overrides the environment and runs LSP server without $HOME defined,
6769
so GetAppConfigDir will not work (it will return relative path ".config/....". instead
6870
of proper absolute "/home/michalis/.config/....").
6971
70-
Emacs LSP client doesn't have this problem. }
72+
Emacs LSP client doesn't have this problem.
73+
74+
CGE integration on https://github.com/castle-engine/castle-engine-vscode/
75+
also doesn't have this problem. }
7176
if GetEnvironmentVariable('HOME') = '' then
7277
begin
73-
FileName := '/home/' + GetUserName(FpGetUID) + '/.config/pasls/castle-pasls.ini';
78+
ConfigFileName := '/home/' + GetUserName(FpGetUID) + '/.config/pasls/castle-pasls.ini';
7479
end else
7580
{$endif}
76-
FileName := IncludeTrailingPathDelimiter(GetAppConfigDir(false)) + 'castle-pasls.ini';
81+
ConfigFileName := IncludeTrailingPathDelimiter(GetAppConfigDir(false)) + 'castle-pasls.ini';
7782

78-
//WriteLn('Reading config from ', FileName);
79-
UserConfig := TIniFile.Create(FileName);
83+
//WriteLn('Reading INI config from ', ConfigFileName);
84+
UserConfig := TIniFile.Create(ConfigFileName);
85+
86+
// create UserConfigPaths
87+
PathsFileName := ChangeFileExt(ConfigFileName, '-paths.txt');
88+
UserConfigPaths := TStringList.Create;
89+
if FileExists(PathsFileName) then
90+
UserConfigPaths.LoadFromFile(PathsFileName);
8091
end;
8192

8293
{ Detect Castle Game Engine path using various methods.
@@ -237,6 +248,23 @@ function ExtraFpcOptions: String;
237248
finally FreeAndNil(CastleFpcCfg) end;
238249
end;
239250

251+
procedure AddPathsFromUserConfigPaths;
252+
var
253+
S, Trimmed: String;
254+
begin
255+
for S in UserConfigPaths do
256+
begin
257+
Trimmed := Trim(S);
258+
// ignore empty lines and comments
259+
if (Trimmed <> '') and (Trimmed[1] <> '#') then
260+
begin
261+
Result := Result +
262+
' ' + QuoteFpcOption('-Fu' + Trimmed) +
263+
' ' + QuoteFpcOption('-Fi' + Trimmed);
264+
end;
265+
end;
266+
end;
267+
240268
const
241269
{ Add the same syntax options as are specified by CGE build tool in
242270
castle-engine/tools/build-tool/code/toolcompile.pas .
@@ -271,8 +299,9 @@ function ExtraFpcOptions: String;
271299
Inc(ExtraOptionIndex);
272300
Result := Result + ' ' + QuoteFpcOption(ExtraOption);
273301
end;
274-
end;
275302

303+
AddPathsFromUserConfigPaths;
304+
end;
276305

277306
procedure ParseWorkspacePaths(const ProjectSearchPaths, ProjectDirectory: String);
278307

@@ -337,4 +366,5 @@ finalization
337366
FreeAndNil(WorkspaceAndEnginePaths);
338367
FreeAndNil(WorkspacePaths);
339368
FreeAndNil(UserConfig);
369+
FreeAndNil(UserConfigPaths);
340370
end.

0 commit comments

Comments
 (0)