Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileBasename without extension #71

Closed
ChristianRinn opened this issue Aug 24, 2016 · 5 comments
Closed

fileBasename without extension #71

ChristianRinn opened this issue Aug 24, 2016 · 5 comments
Assignees

Comments

@ChristianRinn
Copy link

First of all thank you very much for this plugin. This is not a bug but a feature request (closely related to microsoft/vscode#1104).

I've managed to debug embedded applications with the following launch.json config (on Linux). Maybe you can add it to the readme, so if others wanted to do similar stuff, they would get it working faster.

{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "gdb",
"gdbpath": "arm-none-eabi-gdb",
"request": "attach",
"cwd": "${workspaceRoot}",
"executable": "${cwd}/blink.elf",
"target": "localhost:3333",
"remote": true
}
]
}

The one thing that bothers me though, is that you can not use ${fileBasename} as a variable for the executable (blink.elf in my case) because it includes the extension (.c) as well.
I think it should be something like
"executable": "${cwd}/${FileBasenameNoExt}.elf"

There is already a supposal for this (including code) here:
https://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/8945725-add-filebasenamenoext-to-tasks-json-variables

Would be awesome if you could implement that as a custom variable for code-debug, since the upstream issue does not seem to be as important to be resolved but for debugging I think it would be great.

@WebFreak001
Copy link
Owner

where is the ${fileBasename} variable coming from though? I'm not quite sure if code-debug can actually read that variable

@ChristianRinn
Copy link
Author

I don't know where exactly it is coming from but it is implemented for launch.json as well as tasks.json. For all other variables that are built in you can have a look here:
https://code.visualstudio.com/docs/editor/tasks#_variable-substitution

The thing though with ${fileBasename} is that it is implemented through the node.js function path.basename which in turn follows the (irritational) behaviour of the shell and returns the whole filename including the extension. So if my file I want to debug is located in "/my/path/to/my/source.c", ${fileBasename} will return "source.c" instead of "source". It used to return the whole path on Linux (and maybe OS X as well) which seems to be standard nodejs behaviour but that was not intended and though was considered a bug in vs-code and fixed (microsoft/vscode#6623).

A nodejs function that strips away the extension is already there:
https://nodejs.org/api/path.html#path_path_basename_path_ext

I just stumbled about an implementation of it in another vs-code addon:
https://github.com/emeraldwalk/vscode-runonsave/blob/master/src/extension.ts#L174

If I only would know a little more about Typescript I would probably just have implemented it myself and send you a pull request but unfortunately this is a little bit too cryptic for me right now, sorry ;)

@WebFreak001
Copy link
Owner

ah so its the current file, ok that is easily done then

@WebFreak001
Copy link
Owner

ok you can now use it using ${command.FileBasenameNoExt} for just the basename without extension and with ${command.FileNameNoExt} if you also want the directory.

I can't omit the command. part because it comes from vscode

@WebFreak001
Copy link
Owner

Im also gonna bump the version and publish it once the travis test is done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants