Skip to content

Commit

Permalink
Add ctrl+click on include directive to open file
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Oct 1, 2023
1 parent baed483 commit fd13dcc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Source/codetools/simba.ide_codetools_insight.pas
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ function TCodeinsight.DoFindInclude(Sender: TmwBasePasLex; var FileName: String;

Include := CodetoolsIncludes.Get(Sender);
if (Include <> nil) then
begin
FScriptParser.Root.Items.Add(TDeclaration_IncludeDirective.Create(FScriptParser, Include.FileName));
FIncludeParsers.Add(Include);
end;
end;

function TCodeinsight.DoFindPlugin(Sender: TmwBasePasLex; var FileName: String): Boolean;
Expand Down
22 changes: 18 additions & 4 deletions Source/codetools/simba.ide_codetools_parser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ TDeclaration_Keyword = class(TDeclaration)
end;

TDeclaration_Anchor = class(TDeclaration);
TDeclaration_IncludeDirective = class(TDeclaration)
public
FileName: String;

constructor Create(AParser: TCodeParser; AFileName: String); reintroduce;
end;

TDeclaration_WithStatement = class(TDeclaration);
TDeclaration_WithVariableList = class(TDeclaration);
Expand Down Expand Up @@ -364,6 +370,10 @@ TCodeParser = class(TmwSimplePasPar)
function GetCaretPos: Integer;
procedure SetCaretPos(const Value: Integer);

function PushStack(const AClass: TDeclarationClass): TDeclaration; inline;
function PushStub(const AClass: TDeclarationClass): TDeclaration; inline;
procedure PopStack; inline;

procedure EmptyVarStub(const VarStub: TDeclaration_VarStub; const VarClass: TDeclaration_VarClass);
procedure EmptyParamStub(const ParamStub: TDeclaration_ParamStub);

Expand All @@ -372,10 +382,6 @@ TCodeParser = class(TmwSimplePasPar)
function InDeclaration(const AClassType1, AClassType2, AClassType3: TDeclarationClass): Boolean; overload;
function InDeclaration(const AClassType1, AClassType2, AClassType3, AClassType4: TDeclarationClass): Boolean; overload;

function PushStack(const AClass: TDeclarationClass): TDeclaration; inline;
function PushStub(const AClass: TDeclarationClass): TDeclaration; inline;
procedure PopStack; inline;

procedure ParseFile; override;
procedure OnLibraryDirect(Sender: TmwBasePasLex); override; //Plugins
procedure OnIncludeDirect(Sender: TmwBasePasLex); override; //Includes
Expand Down Expand Up @@ -438,6 +444,7 @@ TCodeParser = class(TmwSimplePasPar)
procedure EnumeratedTypeItem; override; //Enum Element
procedure QualifiedIdentifier; override; //Enum Element Name
public
property Root: TDeclaration read FRoot;
property Plugins: TStringList read FPlugins;

property FileName: String read GetFileName;
Expand Down Expand Up @@ -577,6 +584,13 @@ constructor TDeclaration_Keyword.Create(Keyword: String);
isKeyword := True;
end;

constructor TDeclaration_IncludeDirective.Create(AParser: TCodeParser; AFileName: String);
begin
inherited Create(AParser, nil, AParser.Lexer.TokenPos, AParser.Lexer.TokenPos + AParser.Lexer.TokenLen);

FileName := AFileName;
end;

constructor TDeclaration_Type.Create(AParser: TCodeParser; AOwner: TDeclaration; AStart: Integer; AEnd: Integer);
begin
inherited Create(AParser, AOwner, AStart, AEnd);
Expand Down
7 changes: 7 additions & 0 deletions Source/simba.ide_showdeclaration.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ procedure FindAndShowDeclaration(Script, ScriptFileName: String; CaretPos: Integ
Codeinsight.SetScript(Script, ScriptFileName, CaretPos);
Codeinsight.Run();

Decl := Codeinsight.ScriptParser.Items.GetByPosition(CaretPos);
if (Decl is TDeclaration_IncludeDirective) then
begin
SimbaScriptTabsForm.Open(TDeclaration_IncludeDirective(Decl).FileName);
Exit;
end;

Decl := Codeinsight.ParseExpression(What, []);
if (Decl <> nil) then
begin
Expand Down

0 comments on commit fd13dcc

Please sign in to comment.