dseight / vscode-disasexpl

Disassembly Explorer for VS Code
MIT License
48 stars 11 forks source link

The path has some problems #1

Closed mxdh closed 5 years ago

mxdh commented 5 years ago

Win10 x64 1809 My English is not good. provider.ts

function resolvePath(path: string, associated: string): string {
    if (workspace.workspaceFolders === undefined) {
        return path;
    }

    let parsedFilePath = Path.parse(path);
    let parsedWorkspacePath = Path.parse(workspace.workspaceFolders[0].uri.path);

    let variables: any = {
        // the path of the folder opened in VS Code
        'workspaceFolder': parsedWorkspacePath.dir,
        // the name of the folder opened in VS Code without any slashes (/)
        'workspaceFolderBasename': parsedWorkspacePath.name,
        // the current opened file
        'file': path,
        // the current opened file relative to workspaceFolder
        'relativeFile': Path.relative(parsedWorkspacePath.dir, path),
        // the current opened file's basename
        'fileBasename': parsedFilePath.base,
        // the current opened file's basename with no file extension
        'fileBasenameNoExtension': parsedFilePath.name,
        // the current opened file's dirname
        'fileDirname': parsedFilePath.dir,
        // the current opened file's extension
        'fileExtname': parsedFilePath.ext,
    };

    const variablesRe = /\$\{(.*?)\}/g;
    const resolvedPath = associated.replace(variablesRe, (match: string, name: string) => {
        const value = variables[name];
        if (value !== undefined) {
            return value;
        } else {
            // leave original (unsubstituted) value if there is no such variable
            return match;
        }
    });

    // normalize a path, reducing '..' and '.' parts
    return Path.normalize(resolvedPath);
}

For example,if my source file is E:/code/a.cpp,and my "disasexpl.associations" setting is the default:

"disasexpl.associations": {
            "**/*.c": "${fileDirname}/${fileBasenameNoExtension}.S",
            "**/*.cpp": "${fileDirname}/${fileBasenameNoExtension}.S"
        }

This function returns \e:\code\a.S So I think it should be this:

function resolvePath(path: string, associated: string): string {
    if (workspace.workspaceFolders === undefined) {
        return path;
    }

    let parsedFilePath = Path.parse(path);
    let parsedWorkspacePath = Path.parse(workspace.workspaceFolders[0].uri.path);

    let variables: any = {
        // the path of the folder opened in VS Code
        'workspaceFolder': parsedWorkspacePath.dir,
        // the name of the folder opened in VS Code without any slashes (/)
        'workspaceFolderBasename': parsedWorkspacePath.name,
        // the current opened file
        'file': path,
        // the current opened file relative to workspaceFolder
        'relativeFile': Path.relative(parsedWorkspacePath.dir, path),
        // the current opened file's basename
        'fileBasename': parsedFilePath.base,
        // the current opened file's basename with no file extension
        'fileBasenameNoExtension': parsedFilePath.name,
        // the current opened file's dirname
        'fileDirname': parsedFilePath.dir,
        // the current opened file's extension
        'fileExtname': parsedFilePath.ext,
    };

    const variablesRe = /\$\{(.*?)\}/g;
    const resolvedPath = associated.replace(variablesRe, (match: string, name: string) => {
        const value = variables[name];
        if (value !== undefined) {
            return value;
        } else {
            // leave original (unsubstituted) value if there is no such variable
            return match;
        }
    });

    return resolvedPath;
}
dseight commented 5 years ago

Thank you for submitting an issue! This problem is still not solved, so I think that issue should not be closed yet.