I have some generated codes which contain comments like // #line 56"/home/alan/quicker/painful/Worker.actor.cpp"
Is it possible for vscode or any vscode extension to open the file path and jump to the corresponding line as described in this comment with just one simple mouse click?
You can use HTML Related Links
This tool allows you to extract file path and line/char positions and open the file there. The file links are in a separate view of the explorer bar.
If you also have relative paths make a second entry.
You can make global links but also scope them to a languageId. Here I have chosen cpp
"html-related-links.include": {
"cpp": [
{
"find": "// #line (\d+)\"(/[^\"])\"",
"filePath": "$2",
"isAbsolutePath": true,
"lineNr": "$1"
}
]
}
Related
I often find myself working on file test-1a.robot and I want to open test-1b.robot, which is the next alphabetical file in the editor list.
With the files are open and I have a "sort tabs" extension enabled I can use ctrl+pgup and ctrl+pgdn which is already something, but I'd like to have it even without the tab sorting or opening files in advance.
Maybe you need to train yourself in the following key combo:
Ctrl+Shift+E DownArrow Enter
I tried to use multi-command to create a combo of
show explorer tab
go to next file down
open this file
For (1.) I could find a command, it sets the focus on the current file in the Explorer.
Edit With the tip from mark for the commands to type the cursor down (2) and select command (3) in listboxes.
You can add this to your settings and create a key binding for this new command
"multiCommand.commands": [
{
"command": "multiCommand.openNextABCFile",
"sequence": [
"workbench.view.explorer",
"list.focusDown",
"list.select"
]
}
]
It opens the next alphabetical filename in preview mode.
I work with big flat database files which I like to inspect at line/column.
I have a tool which generates a log with hundreds of lines like:
code --goto path/to/my/file:line:column
Visiting one such a spot works ok if I throw one such a line into the command line window and click it from there, but not from the editor (at least I have not found the way)
I would like to be able to have this log file open in the VSCode editor and hover/click in every line which would take me to the spot I want to visit in the big db file. Is this possible at all?
Should I convert my log file to some script format which supports the hover and click functionality?
Is there otherwise any extension available which can do the trick here?
Thanks a lot.
Miguel
Edit
Using HTML Related Links v0.9.0
I guess we're almost there but it's still not working for me.
The concrete scenario I have is: I have a file
d:\Users\Abc.def\Git\lingware-data\test\spx\spm\spm_cfg3\spm_cfg3_tst_row_valid_lng_abbr.dbr
containing several lines of the type
code --goto d:\Users\Abc.def\Git\lingware-data\dct\spx\dct.u08:176:36
(probably code is not needed, I tried with and without it)
In my settings.json file:
"files.associations": { ".u08": "csv (pipe)", ".dbr": "html" },
"editor.largeFileOptimizations": false,
"html-related-links.include": {
"html": [
{ "find": "--goto ([a-z:]+[^:]+):(\\d+):(\\d+)",
"filePath": "$1",
"lineNr": "$2",
"charPos": "$3"
}
]
}
if I use "plaintext" as languageId I don't get the HTML related links section displayed in the Explorer area, so I am using "html" - I have updated to v0.9.0 of the extension, and what I continue seeing in the explorer view is:
"d:\Users\Abc.def\Git\lingware-data\dct\spx\dct.u08 d:\Users\Abc.def\Git\lingware-data\test\spx\spm\spm_cfg3\d:\Users\Abc.def\Git\lingware-data\dct\spx\dct.u08"
If I click on it nothing happens I hope this is more or less clear.
What am I doing wrong?
*** edit ***
Installed v0.9.1. Enabled Developer console to debug click behavior on a row. What get now is:
[Extension Host] Clicked on: d:\Users\Miguel.Duran\Git\lingware-data\dct\spx\dct.u08
console.ts:137 [Extension Host] goto: 175:28
You can use the extension HTML Related Links v0.9.0 (it not only applies to HTML)
Define this in settings.json
"html-related-links.include": {
"plaintext": [
{ "find": "--goto ([^:]+):(\\d+):(\\d+)",
"filePath": "$1",
"isAbsolutePath": true,
"lineNr": "$2",
"charPos": "$3"
}
]
},
"html-related-links.removePathFromLabel": true
After loading the log file you can lock the Explorer View HTML RELATED LINKS to this file. Use lock button in top right of the view. Now only changes to this log file will update the view.
In an absolute path the label will contain the path and the view adds the directory path at the end. You can remove the path from the label with the setting html-related-links.removePathFromLabel
Click on a row in the view and that file will be opened to the given line:char position.
If on Windows the path is absolute you have to specify the drive first because it contains a :
"find": "--goto ([a-z]:[^:]+):(\\d+):(\\d+)"
Edit
There was a small typo in the regular expression string (need escaping the escape char).
Add possibility for absolute paths.
I would like to be able to have this log file open in the VSCode editor and hover/click in every line which would take me to the spot I want to visit in the big db file.
Is this possible at all?
If you visualize your file in a VSCode terminal, VSCode 1.70 (July 2022) will offer a way.
See issue 140780 ("Jump to line+column in terminal links (format <path> l:c)"), PR 153957 ("Detect terminal links with space, then line:col") and PR 155904 ("Ensure folders with spaces don't impact link line/col")
To test, you can open a terminal and run echo ./myFile.txt 10:5 (replacing the filename with one that exists).
When you click to open the file, it should open to line 10, column 5.
This is available today (July 2022) in Code insiders.
if there is a file called javascript.json --> then every .js file reads its content when u using VSC.
I would like to not only read snippets from javascript.json but from javascript2.json as well when editing a js file in vsc. (or any other random name, the main thing is to read snippets for javascript from multiple json files)
Is there a way to do this?
You can have additional snippet files in your workspace .vscode directory.
The file has the extension: .code-snippets
You can limit the language for a snippet by using the scope attribute.
{
// Place your test workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
"Print to console": {
"scope": "javascript,typescript",
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
}
Often, I am editing files that reference other files, and I would like to be able to Cmd-click the filenames to open the referenced file.
An example would be a configuration file that points to another config file, cf. the following JSON snippet:
"structureDefinitionFilename": {
"doc": "Filename of the Structure definitions",
"default": "./structureDefinition.json"
},
When my cursor is on the ./structureDefinition.json, I would like to be able to run a command that opens that file. (I am not using the mouse a lot, so I was just mentioning Cmd-click as an example.)
Another example would be Python source code which opens a data file:
with open('data/structures.lst') as f:
...
Again, it would be nice to be able to quickly open data/structures.lst.
Is there any built-in method or an extension that allows this?
Is it possible to configure VS Code to use C-style comments (/**/) instead of C++ style ones (//) for C code only? My Gooogle-fu might be weak, but I haven't found any useful solution to it so far.
Select the line or lines then press Ctrl + Shift + A.
You can actually redefine it entirely to your liking, but it will require some fiddling with the package.json of the C/C++ extension.
This file will probably be located (at least on my Ubuntu it is) in ~/.vscode/extensions/ms-vscode.cpptools-YOUR_VERSION_NUMBER. So open it
code ~/.vscode/extensions/ms-vscode.cpptools-YOUR_VERSION_NUMBER/package.json
in terminal.
In this file you need to locate an object named "contributes".
Within this object you'll need to create an array called "languages" and add a language object:
"languages": [
{
"id": "c",
"extensions": [
".c", ".h"
],
"configuration": "./my-c-configuration.json"
}
]
now the path in the configuration property needs to point to another .json file in which you will add the new definition for the comment command:
(in the "my-c-configuration.json" file, created in the same directory)
{
"comments": {
"lineComment": [ "/*", "*/" ],
"blockComment": [ "/*", "*/" ]
}
}
Save both files, reopen the VSCode, and that's all.
Was this changed ?
To me, it works with Ctrl+Alt+A.
It's July, 2020 and latest vs code stable version is Version 1.47.
Toggle block comment shortcut is : Shift+Alt+A.
Official Source : VS-Code Keyboard Shortcuts