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

Rename Symbol is inconsistent #124

Closed
AndreHorst opened this issue Jul 5, 2019 · 5 comments
Closed

Rename Symbol is inconsistent #124

AndreHorst opened this issue Jul 5, 2019 · 5 comments
Labels

Comments

@AndreHorst
Copy link

Hello!
I just tried "Rename Symbol" to change a variable name across the project.

(Just to clarify, this is essentially a refactoring process, correct?)

Anyway, sometimes it renames the symbol, but sometimes not and then not even in the same file. Unfortunately, I could not find a pattern so far, sorry.

Steps:
Pressing F2 (or right-click "Rename Symbol") in order to rename
MAIN_PLUGIN_ROOT_FOLDER to test_MAIN_PLUGIN_ROOT_FOLDER

fortls_issue_1

The variable which I selected gets renamed accordingly:
fortls_issue_2

However, further down the same source file, it sometimes apply the change, and sometimes not:
fortls_issue_3

Am I doing something wrong or is this a bug?

Hope to hear from you soon!

@hansec
Copy link
Owner

hansec commented Jul 5, 2019

Thanks for the report! I suspect this is a bug, likely due to the fairly complicated nature of that source line. Can you add a couple of source code examples here (not screenshots) where this does not work?

@AndreHorst
Copy link
Author

AndreHorst commented Jul 7, 2019

Alright, I narrowed it down! And it's weird ;-)

Apparently, renaming the symbol does not work of the following two conditions apply:

  1. You use it in a write statement, combined with other strings
  2. a single preceding string contains a single quotation mark '

Example:

Originial State, prior to "rename symbol":

   character(len=255) :: ORIGINAL_NAME

    ! << "rename-symbol" works
    ORIGINAL_NAME = "Testing"

    ! << "rename-symbol" works
    write(*,*) ORIGINAL_NAME 
    
    ! << "rename-symbol" works
    write(*,'(A)') "This is a test with NO quotation mark in this string:  ",trim(adjustl(ORIGINAL_NAME)) 

    ! << "rename-symbol" does not work
    write(*,'(A)') "This is also a test, but with a quotation mark BEFORE the variable call: ' ", trim(adjustl(ORIGINAL_NAME)) 

    ! << "rename-symbol" works
    write(*,'(A)') "This is also a test, but with a quotation mark BEFORE the variable call: ' ","a second quotation mark: ' ", trim(adjustl(ORIGINAL_NAME)) 

     ! << "rename-symbol" works
    write(*,'(A)') trim(adjustl(ORIGINAL_NAME)), "This is also a test, but with a quotation mark ' after the variable call"

Changed State, after using "rename symbol":

  character(len=255) :: RENAMED_VARIABLE_NAME 

    ! << "rename-symbol" works
    RENAMED_VARIABLE_NAME  = "Testing"

    ! << "rename-symbol" works
    write(*,*) RENAMED_VARIABLE_NAME  
    
    ! << "rename-symbol" works
    write(*,'(A)') "This is a test with NO quotation mark in this string:  ",trim(adjustl(RENAMED_VARIABLE_NAME )) 

    ! << "rename-symbol" does not work
    write(*,'(A)') "This is also a test, but with a quotation mark BEFORE the variable call: ' ", trim(adjustl(ORIGINAL_NAME)) 

    ! << "rename-symbol" works
    write(*,'(A)') "This is also a test, but with a quotation mark BEFORE the variable call: ' ","a second quotation mark: ' ", trim(adjustl(RENAMED_VARIABLE_NAME )) 

     ! << "rename-symbol" works
    write(*,'(A)') trim(adjustl(RENAMED_VARIABLE_NAME )), "This is also a test, but with a quotation mark ' after the variable call"

I hope you can work with that? If not, please let me know how I can help!

@AndreHorst
Copy link
Author

Another example:

Originial State, prior to "rename symbol":

    character(len=255) :: ORIGINAL_NAME

    call do_someting("test ' ",0,file_id,cbuf,ORIGINAL_NAME)
    call do_someting("test ' ' ",0,file_id,cbuf,ORIGINAL_NAME)
    call do_someting("test",0,file_id,cbuf,ORIGINAL_NAME," ' ")

Changed State, after using "rename symbol":

    character(len=255) :: RENAMED_VARIABLE_NAME 

    call do_someting("test ' ",0,file_id,cbuf,ORIGINAL_NAME)
    call do_someting("test ' ' ",0,file_id,cbuf,RENAMED_VARIABLE_NAME )
    call do_someting("test",0,file_id,cbuf,RENAMED_VARIABLE_NAME ," ' ")

@hansec hansec added the bug label Jul 7, 2019
@hansec
Copy link
Owner

hansec commented Jul 7, 2019

Thanks for all the great test cases! I will look into it the next time I get a chance.

@hansec hansec closed this as completed in c0bc996 Jul 9, 2019
@AndreHorst
Copy link
Author

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants