Skip to content

Commit

Permalink
fixed FPM loading bug
Browse files Browse the repository at this point in the history
  • Loading branch information
genericptr committed Jun 26, 2021
1 parent 897337c commit 08e149c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions general.pas
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,24 @@ function TInitialize.Process(var Params : TInitializeParams): TInitializeResult;
exit(false);

Getdir(0, Path);
writeln(StdErr, '► Loading from FPM: ', Path);

// set the CodeTools project directory to match
CodeToolsOptions.ProjectDir := Path;

try
config := TFPMConfig.Create(Path);
finally

writeln(StdErr, '► Loading from FPM: ', Path);
// set the CodeTools project directory to match
CodeToolsOptions.ProjectDir := Path;

ServerSettings.&program := config.GetProgramFile;
for flag in config.GetCodeToolOptions do
ServerSettings.FPCOptions.Add(flag);
config.Free;
except
end;


try
finally
end;

result := true;
end;
Expand Down Expand Up @@ -340,10 +343,14 @@ function TInitialize.Process(var Params : TInitializeParams): TInitializeResult;

// set the project directory based on root URI path
if rootUri <> '' then
CodeToolsOptions.ProjectDir := ParseURI(rootUri).Path;
begin
URI := ParseURI(rootUri);
CodeToolsOptions.ProjectDir := URI.Path + URI.Document;
end;

// print the root URI so we know which workspace folder is default
writeln(StdErr, '► RootURI: ', CodeToolsOptions.ProjectDir);
writeln(StdErr, '► RootURI: ', rootUri);
writeln(StdErr, '► ProjectDir: ', CodeToolsOptions.ProjectDir);

{$ifdef FreePascalMake}
{ attempt to load settings from FPM config file or search in the
Expand All @@ -353,7 +360,7 @@ function TInitialize.Process(var Params : TInitializeParams): TInitializeResult;
arrive in order to the language server, so we can make no assumptions
based on ambigous ordering. }
if ((initializationOptions.config <> '') and LoadFromFPM(initializationOptions.config, CodeToolsOptions)) or
((workspaceFolders.Count = 1) and LoadFromFPM(ParseURI(rootUri).Path, CodeToolsOptions)) then
((workspaceFolders.Count = 1) and LoadFromFPM(CodeToolsOptions.ProjectDir, CodeToolsOptions)) then
begin
// disable other settings which may interfer with FPM
ServerSettings.includeWorkspaceFoldersAsUnitPaths := false;
Expand Down

0 comments on commit 08e149c

Please sign in to comment.