atom-lupa icon indicating copy to clipboard operation
atom-lupa copied to clipboard

Ability to support other languages

Open romans127 opened this issue 8 years ago • 1 comments

Is it possible to extend lupa to support different languages. Possibly allow a configuration key to overwrite the language, or have a mapping of variables classes, objects, and functions then autodetect the languages using atom ?

romans127 avatar May 08 '17 18:05 romans127

It's possible to support different languages, but this is not configurable on end user level yet.

I mean, atom-lupa is just GUI for lupa library (also written by me) which performs static analysis. https://github.com/hex13/lupa

Lupa has plugin based architecture. There is plugin for JavaScript, plugin for Python, plugin for JSON etc. here is code for matching extension to the language plugin. https://github.com/hex13/lupa/blob/master/src/getMappersFor.js Right now this is the only way to add new language (via edit file above) - so you could either hack your local version of lupa (which is in node_modules of your installed version of atom-lupa) or make PR to the Lupa library (although I think maybe it would be good thing to decouple plugins from the library and enable to add plugins without touching Lupa library whatsoever*)

this is example plugin (which analyzes JSON): https://github.com/hex13/lupa/blob/master/plugins/json.js

such plugins return data via callback, for example:

function plugin(file, enc, callback) {
        // ... some code
        callback(null, Object.assign({}, file, {
            metadata: [
               {type: 'function', name: 'foo', loc: {
                    start: {
                        line: 1, column: 0 
                    }, end: {
                        line: 3, column: 0
                    }
               }}, 
               // you can put more elements like above here. 
               // such element is called "entity" in Lupa naming convention
            ]
        }));
}

*and Lupa library would be probably either deprecated or completely rewritten in few months, because I'm making better library for static analysis. Although plugins are mostly wrappers for parsers (for example JSON plugin is wrapper for JSON parser) so it's probable that plugins for Lupa will work (maybe with a little modification) even if Lupa library will be gone or rewritten.

hex13 avatar May 11 '17 16:05 hex13