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 (F2) #169

Open
BlackRam-oss opened this issue Jul 15, 2022 · 10 comments
Open

Rename symbol (F2) #169

BlackRam-oss opened this issue Jul 15, 2022 · 10 comments
Labels
backlog Something that is not a priority and will be addressed in a future release enhancement Small improvements feature-request t:semantic

Comments

@BlackRam-oss
Copy link

https://code.visualstudio.com/docs/editor/refactoring#_rename-symbol

Enabling the renaming of a variable with f2, is a really convenient and safe thing to do (normal replace is very dangerous). but I don't know how complicated it is to implement.

@duckdoom4
Copy link
Collaborator

duckdoom4 commented Jul 15, 2022

We are planning on updating the semantics and features in the next major update (after syntax is complete). This update should make it a lot more easy to link symbols, and linked symbols would allow rename with F2.

Unfortunately it might take a while for us to start working on this feature as we all don't have much spare time atm.

I'll update this ticket as soon as more information is available

@BlackRam-oss
Copy link
Author

Yeah, it seems like a long and repetitive job to update the semantics, looking at the file in syntaxes folder. If you want I can help with that.

@duckdoom4
Copy link
Collaborator

duckdoom4 commented Jul 16, 2022

The plan is to update most of the existing features to use the tokenizer that has already been pushed to the syntax branch.

The next goal is to create a token parser that would build the symbol database and the code graph. I already started some work on this.

Any help would be very much appreciated, I'd say give me a month to finish the above mentioned part and after that it should be easy to use these features to update the rest.

If you'd like to help with something right now, the tokenizer needs a copy of the syntax patterns in typescript. Some of them are already in there, but I didn't update it in a while. I'd love it if you could help me with updating that 😄

(From this file to this file)

@BlackRam-oss
Copy link
Author

BlackRam-oss commented Jul 16, 2022

OK I can make a few.

I didn't find a TokenPattern type, but taking a simple one, just turn the json into an object. ex:

"renpy-statements": {
    "patterns": [
        {
        "include": "#label"
        },
        { "include": "#menu" },
        { "include": "#image" },
        { "include": "#audio" },
        { "include": "#transform" },
        { "include": "#scene" },
        { "include": "#camera" },
        { "include": "#show" },
        { "include": "#with" },
        { "include": "#style-old" },
        { "include": "#use-old" },
        { "include": "#screen-old" },
        { "include": "#return-statements" },
        { "include": "#jump" },
        { "include": "#call" }
    ]
},
const renpyStatements: TokenPattern = {
    patterns: [
        { include: "#label" },
        { include: "#menu" },
        { include: "#image" },
        { include: "#audio" },
        { include: "#transform" },
        { include: "#scene" },
        { include: "#camera" },
        { include: "#show" },
        { include: "#with" },
        { include: "#style-old" },
        { include: "#use-old" },
        { include: "#screen-old" },
        { include: "#return-statements" },
        { include: "#jump" },
        { include: "#call" },
    ]
}

@duckdoom4
Copy link
Collaborator

Yes, that's about the gist of it. You can use the patterns in the comments of that file to convert them a bit more easily.

Those patterns also apply some changes that are required, eg include pattern in not needed and name is converted to token

@duckdoom4
Copy link
Collaborator

TokenPattern is a type. You can find it here

@BlackRam-oss
Copy link
Author

I am converting them, but I have doubts.

I tried did these replacements, but they were all useless because they didn't find anything:

// find: ^( +)"(\w+?)(?:[\-_](\w+?))?(?:[\-_](\w+?))?(?:[\-_](\w+?))?": \{$\n((?:^.*$\n)+?)^\1\},?
// replace with: const \L$2\u$3\u$4\u$5: TokenPattern = {\n$6};

// find: \{ "include": "#?(\w+?)(?:[\-_](\w+?))?(?:[\-_](\w+?))?(?:[\-_](\w+?))?" }
// replace with: \L$1\u$2\u$3\u$4

// find: (?<=^ *|\{ )"comment": "(.*?)"(?=,$| })
// replace with: // $1

// find: (?<=^ *|\{ )"name": "(.*?)"(?=,$| })
// replace with: token: "$1"

// find: (?<=^ *|\{ )"contentName": "(.*?)"(?=,$| })
// replace with: contentToken: "$1"

// find: (?<=^ *|\{ )"(.*?)"(?=: [{["])
// replace with: $1

// find: (?<=(?:^ *|\{ )(?:match|begin|end): /.*?)\\\\(?=.*?/dg,?$)
// replace with: \

// find: (?<=(?:^ *|\{ )(?:match|begin|end): )"(.*?)"(?=,?$)
// replace with: /$1/dg

// Result should be manually fixed
// Make sure to include this in internal captures to detect all newline tokens

Does this string need to be converted? if so I don't think, to know how.
image

name needs to be converted to token? and Does this strings need to be converted? if so I don't think, to know how.
image

@BlackRam-oss
Copy link
Author

https://github.com/DRincs-Productions/vscode-language-renpy/blob/new-syntax/src/tokenizer/token-patterns.ts

here are some conversions, you notice them because they are the ones with the errors, lol

@duckdoom4
Copy link
Collaborator

Yeah, the instructions weren't very clear, they where meant for me. Sorry about that. I'll try to explain.

So, what you do is;

  • You copy the patterns you wish to convert to the .ts file
  • Make sure it is indented correctly and at least one indent away from the start
  • Now use VS code's build in search and replace tool (ctrl + F).
  • Make sure the tool is in regex mode (3rd button)
  • You probably want to select the text you want to perform these actions on before you replace anything
  • One by one use the find: 'pattern' replace with 'pattern' where 'pattern' is placed in the VS tool

Hope that makes it more clear, I could send a visual example if it's still not :)

@duckdoom4
Copy link
Collaborator

duckdoom4 commented Jul 18, 2022

But thanks a lot for the work you did so far! Any bit is already super helpful 🙂

@duckdoom4 duckdoom4 added the backlog Something that is not a priority and will be addressed in a future release label Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Something that is not a priority and will be addressed in a future release enhancement Small improvements feature-request t:semantic
Projects
None yet
Development

No branches or pull requests

2 participants