Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: recursive Folding Block #555

Merged
merged 18 commits into from
Dec 5, 2023
Merged

Conversation

jingjiajie
Copy link
Contributor

@jingjiajie jingjiajie commented Oct 8, 2023

Summary
Added support for recursive Folding Blocks:

Data in Macro
Proc in Macro
/*region*/ in Data
/*region*/ in Proc
/*region*/ in Macro
Data in /*region*/
Proc in /*region*/
Macro in /*region*/
/*region*/ in /*region*/

Testing
How did you test this change?
Every block shows a folding icon.

*region global;
%macro macro1;
    data table1;
        *region data_inner;
        *endregion data_inner;
    run;

    *region proc;
    proc print data=table1;
        *region proc_inner;
        *endregion proc_inner;
    run;
    *endregion proc;
    
%mend;

*region inner;
    /* nothing */
*endregion inner;

*endregion global;

@jingjiajie jingjiajie changed the title Recursive Folding Block feat: recursive Folding Block Oct 8, 2023
@scnwwu scnwwu self-requested a review October 9, 2023 02:00
@2TomLi 2TomLi added this to the 1.5.0 milestone Oct 12, 2023
@scnwwu
Copy link
Member

scnwwu commented Oct 12, 2023

I noticed 2 issues with below code.

*region;
data _null_;
run;
*endregion;
  1. There's no outline for this code in VS Code's Outline panel.
  2. Open context menu from code, select Run Region, no response.

@scnwwu scnwwu linked an issue Oct 19, 2023 that may be closed by this pull request
@jingjiajie
Copy link
Contributor Author

I noticed 2 issues with below code.

*region;
data _null_;
run;
*endregion;
  1. There's no outline for this code in VS Code's Outline panel.
  2. Open context menu from code, select Run Region, no response.

@scnwwu Fixed all.

@Zhirong2022
Copy link
Collaborator

Acceptance Criteria:

1.Make sure there are no regression issues
2.Verify that the DATA regions can be folded correctly
3.Verify that the PROC regions can be folded correctly
4.Verify that Macro regions can be folded as expected
5.Verify that the customized regions can be folded as expected, the matched pair would be
5.1 /*region [optional description] */ /*endregion [optional description] */
5.2 *region [optional description]; *endregion [optional description];
5.3 %*region [optional description] %*endregion [optional description];
6.Verify that the nested regions work as expected
7.Verify that the outline works well
8.Verify that 'Run region' function well
9.Verify 1 to 8 in OS: Windows and Mac
10.Verify 1 to 9 in NLS environment

@2TomLi 2TomLi modified the milestones: 1.5.0, 1.6.0 Oct 26, 2023
@Zhirong2022
Copy link
Collaborator

Zhirong2022 commented Nov 1, 2023

Type the code below, no outline for the customized region and data block.

%macro filenaming;
    %put &copyres;
%mend;
%filenaming;
*region;
data _null_;
run;

@Zhirong2022
Copy link
Collaborator

Type code below and click the first line or the second, open context menu to execute 'Run region'. It will direct to "proc means" block instead of the whole macro block.

%macro reportit(request);
    %if %upcase(&request)=STAT %then
       %do;
          proc means;
             title "Summary of All Numeric Variables";
          run;
       %end;
%mend reportit;

@Zhirong2022
Copy link
Collaborator

Zhirong2022 commented Nov 2, 2023

Perform 'Run region' action on the code below. If click the first line and execute 'Run region', the whole customized block should be ran. And now it will run data block only.

*region;
data _null_;
run; 
proc print data=sashelp.cars;
run;
*endregion;

@Zhirong2022
Copy link
Collaborator

Type the code below, the data block does not fold properly.

*region;
data;
asd;
*endregion;
asd;
run;

image

@jingjiajie
Copy link
Contributor Author

Type the code below, the data block does not fold properly.

*region;
data;
asd;
*endregion;
asd;
run;

image

@Zhirong2022
The folding block doesn't support overlapping. In this case, the custom block and the data block overlaps, so technically either the *region; truncates the data block, or the data block truncates the *region;. But we shouldn't define a behavior for this case because we don't allow this.

Other issues are all fixed~

@@ -225,7 +231,7 @@ export class LexerEx {
i++;
block = blocks[i];
} while (block && !this._isBefore(pos, this._startPos(block))); // |[]
return --i;
return block ? --i : -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, may I know the reason for this change? If there's not a i+1 block, the i block is still valid.
There's a problem with current implementation. With code

data a;
  a;
run;
data b;
  b;
run;

If I put cursor at the start of the line data b (line 4 col 1), click Run Region from context menu, the data b is not run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scnwwu In the recursive senario, if a user clicks the firstline "*region", and run region, it will search the block recursively. First it finds the *region block, then it will check every children blocks [data, proc]. If I let "i block" is still valid when there is not a i-1 block, it will then match the data block instead of the outer *region block. This is a fault.

*region;
data _null_;
run; 
proc print data=sashelp.cars;
run;
*endregion;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jingjiajie,
There's another problem. With below code, put cursor at line 3 col 1, run region will run *region which is wrong.

*region;
proc print data=sashelp.class;
run;proc print data=sashelp.cars;
*endregion;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@Zhirong2022
Copy link
Collaborator

The outline is not proper for some code blocks. Please type the code below to take a look. '%filenaming;' is not a block in such scenario.

*region;
%macro filenaming;
    %put &copyres;
%mend;
%filenaming;
/*region proc statement*/
proc print data=sashelp.cars; run;
/*endregion*/
*region;
data _null_;
run;
*endregion;

@jingjiajie
Copy link
Contributor Author

The outline is not proper for some code blocks. Please type the code below to take a look. '%filenaming;' is not a block in such scenario.

*region;
%macro filenaming;
    %put &copyres;
%mend;
%filenaming;
/*region proc statement*/
proc print data=sashelp.cars; run;
/*endregion*/
*region;
data _null_;
run;
*endregion;

Fixed.

@Zhirong2022
Copy link
Collaborator

The outline is not correct for the code below. The most outer block '%*region' is not shown as expected.

%*region;
%macro filenaming;
    %put &copyres;
%mend;
%filenaming;    
    /*region proc statement*/
    proc print data=sashelp.cars; run;
    /*endregion*/

    *region;
    data _null_;
    run;
    *endregion;

%*endregion;

@scnwwu
Copy link
Member

scnwwu commented Nov 22, 2023

@jingjiajie, thank you for trying this but there's a problem for this approach.
User can directly right click on a line without put cursor on it first. The setContext is an async operation so the menu item can't be updated in time.

@jingjiajie
Copy link
Contributor Author

jingjiajie commented Nov 22, 2023

@jingjiajie, thank you for trying this but there's a problem for this approach. User can directly right click on a line without put cursor on it first. The setContext is an async operation so the menu item can't be updated in time.

@scnwwu Yes, I reproduced this problem. I think we could just run the open code instead of disabling the menu item, if there's no better solution.

@scnwwu
Copy link
Member

scnwwu commented Nov 22, 2023

@jingjiajie, thank you for trying this but there's a problem for this approach. User can directly right click on a line without put cursor on it first. The setContext is an async operation so the menu item can't be updated in time.

@scnwwu Yes, I reptoduced this problem. I think we could just run the open code instead of disabling the menu item, if there's no better solution.

Agreed

@jingjiajie
Copy link
Contributor Author

@jingjiajie, thank you for trying this but there's a problem for this approach. User can directly right click on a line without put cursor on it first. The setContext is an async operation so the menu item can't be updated in time.

@scnwwu Yes, I reptoduced this problem. I think we could just run the open code instead of disabling the menu item, if there's no better solution.

Agreed

done.

client/src/utils/utils.ts Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks unnecessary to change this file now

client/src/commands/run.ts Outdated Show resolved Hide resolved
@scnwwu
Copy link
Member

scnwwu commented Nov 23, 2023

There's a problem. With below code

%macro;
*region;
data;
a;
*endregion;
%mend;
a;

Put cursor at line 6 (start of %mend;), run region, it run whole file. But it should run only the macro region.

@jingjiajie
Copy link
Contributor Author

There's a problem. With below code

%macro;
*region;
data;
a;
*endregion;
%mend;
a;

Put cursor at line 6 (start of %mend;), run region, it run whole file. But it should run only the macro region.

Fixed.

client/src/commands/run.ts Outdated Show resolved Hide resolved
@Zhirong2022
Copy link
Collaborator

Type code below, click line 5 and execute 'Run region' through context menu. It should run filename statement only. And now it will run all the code.

*region;
options set=SAS_HADOOP_JAR_PATH="/third_party/Hadoop/jars/lib";
options set=SAS_HADOOP_CONFIG_PATH="/sasdata/cluster1/conf";
*endregion;
filename foo hadoop 'file1.dat' user='user' pass='apass' recfm=s lrecl=1024 bufferlen=1000000;
data _null_;
   infile foo truncover;
input a $1024.;
put a;
run;

@jingjiajie
Copy link
Contributor Author

Type code below, click line 5 and execute 'Run region' through context menu. It should run filename statement only. And now it will run all the code.

*region;
options set=SAS_HADOOP_JAR_PATH="/third_party/Hadoop/jars/lib";
options set=SAS_HADOOP_CONFIG_PATH="/sasdata/cluster1/conf";
*endregion;
filename foo hadoop 'file1.dat' user='user' pass='apass' recfm=s lrecl=1024 bufferlen=1000000;
data _null_;
   infile foo truncover;
input a $1024.;
put a;
run;

Fixed.

@Zhirong2022
Copy link
Collaborator

All issues have been fixed.

@Zhirong2022 Zhirong2022 added testing-complete Complete the pull requests testing and removed testing Test the pull requests labels Dec 5, 2023
@scnwwu scnwwu merged commit df9594b into sassoftware:main Dec 5, 2023
1 check passed
@Zhirong2022 Zhirong2022 added verified and removed testing-complete Complete the pull requests testing labels Dec 13, 2023
@Zhirong2022 Zhirong2022 added ready for release Code pushed, but not released in VS code marketplace yet and removed verified labels Jan 15, 2024
@jingjiajie jingjiajie deleted the recursive_block branch February 6, 2024 01:54
@Zhirong2022 Zhirong2022 added the automation Issue has been covered by automation test label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation Issue has been covered by automation test ready for release Code pushed, but not released in VS code marketplace yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Outline does not capture steps within macro definitions
4 participants