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

Question: Can a file extension have both a Generic and Dedicated mapper defined? #92

Open
evbrew opened this issue Dec 13, 2023 · 4 comments
Labels

Comments

@evbrew
Copy link

evbrew commented Dec 13, 2023

I have some mappings that are simple and easy with the Generic mapper, but need a Dedicated mapper for a multiline regex case.
Can i use both at the same time or only 1 or the other?

e.g. something like

"codemap.md": "E:\User\Projects\VSCode\mapper_md.js",
"codemap.md": [
{
"pattern": "^(\s*)### (.*)",
"clear": "##",
"prefix": " -",
"icon": "level3"
},
],

@evbrew
Copy link
Author

evbrew commented Dec 13, 2023

sorry, better syntax would be

"codemap.md": [
"E:\User\Projects\VSCode\mapper_md.js",
{
"pattern": "^(\s*)### (.*)",
"clear": "##",
"prefix": " -",
"icon": "level3"
},
],

or

"codemap.md": [
{
"mapperPath": "E:\User\Projects\VSCode\mapper_md.js"
},
{
"pattern": "^(\s*)### (.*)",
"clear": "##",
"prefix": " -",
"icon": "level3"
},
],

@evbrew
Copy link
Author

evbrew commented Dec 13, 2023

I ended up re-implementing my Generic Mapper rules in the Dedicated file.
You were correct, it wasn't that hard - however, i would suggest adding a few more examples for different scenarios just to save implementation time for new users in the future.

`"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 = []; 
    /*
				members structure: [indent]<name>|<line>|<icon>
				indent - the whitespace indent is optional and is used to express the code nesting (if applicable). Indentation wrks pretty much like in Python syntax.
				name - display name of the navigatable code member
				line - line number to navigate to
				icon - name of the predefined icon:
					class
					interface
					function
					property
					document
					level1
					level2
					level3
					none
			*/
			
    try {
        let lines = mapper.read_all_lines(file);
        for (let i=0; i < lines.length; i++) {
                let line_num = i+1;
                let curLine = lines[i].trimStart();
                let nextLine = lines[i+1].trimStart();
                
                if (curLine.startsWith("<!--- -------------------------------------------------------------------------------------------"))
                    members.push(`${nextLine.trim()}|${line_num+1}|level1`);
                if (curLine.startsWith("/*<!--- -------------------------------------------------------------------------------------------"))
                    members.push(`${nextLine.trim()}|${line_num+1}|level1`);
                else if (curLine.startsWith("function "))
                    members.push(`${curLine.substr(9).replaceAll(' {','')}|${line_num}|function`);
                else if (curLine.startsWith('<cffunction name="'))
                    members.push(`${curLine.match(/<cffunction\s+name="([^"]+)"/)[1]}|${line_num}|function`);
                else if (curLine.match(/function \w*/)) {
											let disName = curLine.match(/function (\w*)/)[1].trim();
											if (disName.length > 0)
												members.push(`${disName}|${line_num}|function`);
                }
        }
    }
    catch (error) {
    }
    return members;
}

}
exports.mapper = mapper;`

@evbrew
Copy link
Author

evbrew commented Dec 13, 2023

great extension, love it, thanks!

@oleg-shilo
Copy link
Owner

Thank you, appreciate your feedback :)

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