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

Inclusion of Tcl language #42

Closed
figurcoe opened this issue Aug 29, 2020 · 17 comments
Closed

Inclusion of Tcl language #42

figurcoe opened this issue Aug 29, 2020 · 17 comments

Comments

@figurcoe
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

figurcoe commented Aug 30, 2020 via email

@figurcoe figurcoe mentioned this issue Aug 30, 2020
@oleg-shilo
Copy link
Owner

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

@figurcoe
Copy link
Contributor Author

figurcoe commented Sep 20, 2020 via email

@oleg-shilo
Copy link
Owner

Done. Please update to v1.16.0

@figurcoe
Copy link
Contributor Author

Thanks...

@dmhuffer
Copy link

dmhuffer commented Jun 2, 2021

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
Copy link
Contributor Author

figurcoe commented Jun 2, 2021 via email

@dmhuffer
Copy link

dmhuffer commented Jun 2, 2021

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
Copy link
Contributor Author

figurcoe commented Jun 2, 2021 via email

@dmhuffer
Copy link

dmhuffer commented Jun 9, 2021

@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
Copy link
Contributor Author

figurcoe commented Jun 9, 2021 via email

@dmhuffer
Copy link

dmhuffer commented Aug 4, 2021

@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
Copy link
Contributor Author

figurcoe commented Aug 4, 2021 via email

@dmhuffer
Copy link

dmhuffer commented Aug 4, 2021

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

@figurcoe
Copy link
Contributor Author

figurcoe commented Aug 8, 2021

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
Copy link

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.

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

No branches or pull requests

3 participants