oleg-shilo / codemap.vscode

Code map (syntax tree) of the active document
MIT License
84 stars 28 forks source link

Inclusion of Tcl language #42

Closed figurcoe closed 4 years ago

figurcoe commented 4 years ago

Hi, I've written a simple mapper fort Tcl/iTcl. Would you mind including it? Unfortunately it is rather simplistic, but better than nothing. Do you see the possibility to easily add a few features, like sorting alphabetically or taking a namespace into account?

An example of a tcl-file would be:

namespace eval ggg {

    itcl::class test {
        variable question
        variable answer

        constructor {text} { 
        }

        destructor {
        }

        method query {command {format 0}} {
        }

        method print {} {
        }

    }

    proc create_item {service port} {
    }
}

proc ggg::ttt {} {
}

Mapper:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");

class mapper {

    static read_all_lines(file) {
        let text = fs.readFileSync(file, 'utf8');
        return text.split(/\r?\n/g);
    }

    static generate(file) {
        let members = [];
        try {
            let line_num = 0; 

            const re_proc = new RegExp('^(\\s*)proc\\s+(.+?)(?:\\s*{\\s*)$');
            const re_class = new RegExp('^(\\s*)(?:(?:::)?itcl::)?class\\s+([\\w:]+)');
            const re_variable = new RegExp('^(\\s*)(?:(?:public|private|protected)?\\s+)?variable\\s+(\\w+)');
            const re_constructor = new RegExp('^(\\s*)constructor\\s+(.+?)(?:\\s*{\\s*)$');
            const re_destructor = new RegExp('^(\\s*)destructor');
            const re_method = new RegExp('^(\\s*)(?:(?:public|private|protected)?\\s+)?method\\s+(\\w+.+)(?:\\s*{\\s*)$');
            const re_namespace= new RegExp('^(\\s*)(?:namespace\\s+eval)\\s+(\\w+)');

            mapper
                .read_all_lines(file)
                .forEach(line => {
                    line_num++;
                    //line = line.trimStart();
                    // proc
                    if (re_proc.test(line)) {
                        let result = line.match(re_proc);
                        members.push(`${result[1]}${result[2]}|${line_num}|function`);
                    // itcl::class
                    } else if (re_class.test(line)) {
                        let result = line.match(re_class);
                        members.push(`${result[1]}${result[2]}|${line_num}|class`);
                    // variable
                    } else if (re_variable.test(line)) {
                        let result = line.match(re_variable);
                        members.push(`${result[1]}${result[2]}|${line_num}|property`);
                    // method
                    } else if (re_method.test(line)) {
                        let result = line.match(re_method);
                        members.push(`${result[1]}${result[2]}|${line_num}|function`);
                    // constructor
                    } else if (re_constructor.test(line)) {
                        let result = line.match(re_constructor);
                        members.push(`${result[1]}constructor ${result[2]}|${line_num}|function`);
                    // destructor
                    } else if (re_destructor.test(line)) {
                        let result = line.match(re_destructor);
                        members.push(`${result[1]}destructor|${line_num}|function`);
                    // namespace
                    } else if (re_namespace.test(line)) {
                        let result = line.match(re_namespace);
                        members.push(`${result[1]}${result[2]}|${line_num}|document`);
                    }
            });
        }
        catch (error) {
        }

        return members
    }
}
exports.mapper = mapper;

Thanks for considering.

oleg-shilo commented 4 years ago

Thank you, will incorporate your contributions as soon as I have a chance. Should not take long.

As for namespaces I am not sure it's feasible to do on the plugin level. Detection of the syntactical context (e.g. namespace) is a responsibility of a mapper, not a plugin, which works with all supported file types (languages). In fact some languages do not even support concept of namespaces.

And sorting is a challenge. as it only straightforward for flat tries (lists). If you have an intensive structure then it's tricky to define what are the sorting requirements.

Though it is always possible to sort the items within a node. And may be allow a mapper to express the sorting request (e.g. have a sorting index). I suggest you add sorting as a feature request and let's see if it can be done without breaking the user experience.

figurcoe commented 4 years ago

Hi, Thanks a lot. I only managed to have a quick look at the source code and I'm not really familiar with JavaScript. If you can point me in the right direction, I could try to get something integrated in the mapper. Thanks for your work, this helps a lot with older languages with rather a limited community.

Am August 30, 2020 1:44:17 AM UTC schrieb Oleg Shilo notifications@github.com:

Thank you, will incorporate your contributions as soon as I have a chance. Should not take long.

As for namespaces I am not sure it's feasible to do on the plugin level. Detection of the syntactical context (e.g. namespace) is a responsibility of a mapper, not a plugin, which works with all supported file types (languages). In fact some languages do not even support concept of namespaces.

And sorting is a challenge. as it only straightforward for flat tries (lists). If you have an intensive structure then it's tricky to define what are the sorting requirements.

Though it is always possible to sort the items within a node. And may be allow a mapper to express the sorting request (e.g. have a sorting index). I suggest you add sorting as a feature request and let's see if it can be done without breaking the user experience.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/oleg-shilo/codemap.vscode/issues/42#issuecomment-683364939

oleg-shilo commented 4 years ago

I have integrated your TCL mapper. Will be available in the very next release

figurcoe commented 4 years ago

Thanks a lot

Am September 19, 2020 1:44:27 PM UTC schrieb Oleg Shilo notifications@github.com:

I have integrated your TCL mapper. Will be available in the very next release

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/oleg-shilo/codemap.vscode/issues/42#issuecomment-695215307

oleg-shilo commented 4 years ago

Done. Please update to v1.16.0

figurcoe commented 4 years ago

Thanks...

dmhuffer commented 3 years ago

I am having trouble getting the new mapper_tcl working. Before I had the below text in the settings file and it worked.

"codemap.cgi": [

{
  "pattern": "^proc \\w*",
  "icon": "function"
}

],

figurcoe commented 3 years ago

Interesting, I changed just the file and on my PC or was working flawlessly. I'll look into it on the weekend. Anything particular, I should look out for?

Am June 2, 2021 6:02:46 PM UTC schrieb dmhuffer @.***>:

I am having trouble getting the new mapper_tcl working. Before I had the below text in the settings file and it worked.

"codemap.cgi": [

{ "pattern": "^proc \w*", "icon": "function" } ],

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/oleg-shilo/codemap.vscode/issues/42#issuecomment-853266932

dmhuffer commented 3 years ago

not really sure but I know that I opened your example file in my vscode and codemap did not work on it either. I dont know if I need to update something on my end or what.

figurcoe commented 3 years ago

Ok, i'll give that a try. I tested it with a different file I believe.

Am June 2, 2021 6:15:36 PM UTC schrieb dmhuffer @.***>:

not really sure but I know that I opened your example file in my vscode and codemap did not work on it either. I dont know if I need to update something on my end or what.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/oleg-shilo/codemap.vscode/issues/42#issuecomment-853275335

dmhuffer commented 3 years ago

@figurcoe have you been able to test more? I just reinstalled vscode to see if I had other settings wrong. Installed just Codemap and tcl language support and still not getting code map to work unless I change the settings file to have what I put above.

figurcoe commented 3 years ago

Well, I tested it on the weekend and there was no problem for me. What I don't understand, is why my answer doesn't show...

What I did was

  1. Uninstall the extension
  2. Reinstall from market place
  3. Patch the mapper for TCL with the new one
  4. Copy the test data from the original thread

For me it worked flawlessly with spaces and tabs as indentation characters. However, I tested it under Linux.

If you have a packed version, then I can install that one and test it.

Am June 9, 2021 1:43:49 PM UTC schrieb dmhuffer @.>: @. have you been able to test more? I just reinstalled vscode to

see if I had other settings wrong. Installed just Codemap and tcl language support and still not getting code map to work unless I change the settings file to have what I put above.

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/oleg-shilo/codemap.vscode/issues/42#issuecomment-857706239

dmhuffer commented 3 years ago

@figurcoe Sorry for the long time for a response. I tried to mimic what you did with no avail. I am not sure how or what you mean when you are talking about a packaged version. If you know where I could find instructions on that I could try for you. All I know is when I update the settings.json and add what is below It works flawlessly for me. I do not know if its something to do with my settings and not looking at the mapper or something?

"codemap.tcl": [
        {
            "pattern": "^proc \\w*",
            "icon": "function"
          }
    ]
figurcoe commented 3 years ago

Hi, I would need to check, but I believe I was talking about the version, I can download from the marketplace.

I'll check it on the weekend. Thanks for your reply.

dmhuffer commented 3 years ago

yes I am on version 1.16.1 which is just the most recent version of it.

figurcoe commented 3 years ago

Hi,

so I tried it and it seems to work flawlessly for me. What I did:

  1. Fresh install of VS Code on a windows machine
  2. Install Copemap from marketplace
  3. Quit VS Code
  4. Download https://raw.githubusercontent.com/figurcoe/codemap.vscode/e4ebdf5c12d9a84e01f71780368f3517d7176e89/src/mapper_tcl.ts and save it to %HOMEPATH%\.vscode\extensions\oleg-shilo.codemap-1.16.1\out\src replacing the extension ".ts" with ".js"
  5. Restart VS Code
  6. Open test-files

That was working for me.

These were my test-files. Rename the ".txt" to ".tcl" again: test_spaces.txt test_tabs.txt image

Edit: path under 4. lost the "\" after %HOMEPATH%, changed first "\" to "\"

dmhuffer commented 3 years ago

So I have found my issue but im not sure what is causing it. For some back ground for how I usually work with my tcl files. I use a Extension called SSH FS to open my server as a work space and grab my files to edit that way. With the way I showed above within the settings file code map worked perfectly fine when I opened my files from the server using SSH FS. With the mapper_tcl it does not but if I make a local copy of my tcl file the mapper works correctly.