oleg-shilo / codemap.vscode

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

How to register a custom mapper with a complex file extension #59

Open smartev3 opened 3 years ago

smartev3 commented 3 years ago

We made a custom JS mapper for CSDL XML files (OData CSDL XML is defined at http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/cs01/odata-csdl-xml-v4.01-cs01.html).

However in the VSCode JSON Settings we have to register it under the "codemap.xml" key, whereas we would rather register it under a key "codemap.csdl.xml" and have it apply only to XML files ending with the file extension ".csdl.xml".

Just wondering how to achieve it.

Here is the JS code.

"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; 
            let image_index = 1;
            mapper
                .read_all_lines(file)
                .forEach(line => {
                    line_num++;
                    line = line.trimStart();
                    let firstIndex = line.indexOf('"');
                    let secondIndex = line.substr(firstIndex+1).indexOf('"');
                    if (line.startsWith("<Schema"))
                        members.push(`${line.substr(1, firstIndex+secondIndex+1)}|${line_num}|level1`);
                    else if (line.startsWith("<EntityType") || line.startsWith("<ComplexType") 
                        || line.startsWith("<EnumType") || line.startsWith("<TypeDefinition") 
                        || line.startsWith("<Term") || line.startsWith("<Action") 
                        || line.startsWith("<Function") || line.startsWith("<EntityContainer"))
                        members.push(`    ${line.substr(1, firstIndex+secondIndex+1)}|${line_num}|level2`);

            });
        }
        catch (error) {
        }
        return members;
    }
}
exports.mapper = mapper;
oleg-shilo commented 3 years ago

It will require changing the fila extension handling algorithm of the extension. But... I like the idea nd making the issue inti "Enhancement". Will implement it in the next release

arathburgos05 commented 7 months ago

Hi @oleg-shilo,

I'm also interested on this feature. Is it implemented in v1.23.0? Is not the case, there is planned to implement it? (or any way in which I can use it for custom extensions, for example filename.xml.m4, filename.xdm.m4 or filename.epc.m4).

Regards. Thanks for your extension, it is very useful.

oleg-shilo commented 7 months ago

Sorry guys, I am struggling to keep up with my other open-source projects. So this one is still in the queue...

oleg-shilo commented 6 months ago

But I will try to squeeze it into the next week.

oleg-shilo commented 6 months ago

Done: https://github.com/oleg-shilo/codemap.vscode/releases/tag/v1.24.0.0

ATTENTION:

Complex extensions should be dot-escaped in the config file with the / character due to the VSCode limitations of not handling dots in the config names correctly. IE the mapper configuration for the document.git.md file should be encoded in the setting.jeson as "codemap.git/md": "config:codemap.md",