codemap.vscode icon indicating copy to clipboard operation
codemap.vscode copied to clipboard

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

Open evbrew opened this issue 1 year ago • 4 comments

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 avatar Dec 13 '23 17:12 evbrew

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 avatar Dec 13 '23 19:12 evbrew

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 avatar Dec 13 '23 19:12 evbrew

great extension, love it, thanks!

evbrew avatar Dec 13 '23 19:12 evbrew

Thank you, appreciate your feedback :)

oleg-shilo avatar Dec 15 '23 13:12 oleg-shilo