Skip to content

Async support for custom global.formatFilepath #5546

Description

@asmodeus812

It would be quite useful to have global.formatFilepath support async as well, since we can then call a vim/nvim function to do the transformation as well, as of now it is a bit tricky because we might have to duplicate functional logic between both a lua/vimscript plugin and coc, that does common transformationn such as converting/extracting information from uri names.

"use strict";
const { workspace } = require("coc.nvim");

exports.activate = (context) => {
    console.log("Initilalizing coc-extension formatter");
    const nvim = workspace.nvim;

global.formatFilepath = function (uri) {
// would like to replace this with a better implementation that is available to me through a lua/vimscript plugin.
    if (uri.startsWith('jdt:/')) {
        const match = uri.match(regex);
        const module = match[1].replace(/\.jar$/, "");
        const classPath = match[2].replace(/\//g, ".");
        const versionPart = match[3].match(/(?:jdk|openjdk)[^\\/]*@(\d+)/);
        const version = versionPart ? versionPart[1] : null;

        if (version) {
            return `jdk-${version}:${classPath}`;
        } else {
            return `${module}:${classPath}`;
        }
    } else {
        return uri
    }
}
    context.subscriptions.push({
        dispose: () => {
            delete global.formatFilepath;
        }
    });
};

exports.deactivate = () => {
    delete global.formatFilepath;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions