0

I'm trying to improve the log I sometimes write to check what variable I have at a certain point or what value a function return, and in certain case find a problematic line (when I don't use a debugger).

So I made the following live template (taking JS example):

console.log("Line $LINE$ in $FILE$");
$END$

$LINE$:

lineNumber()

$FILE$:

fileName()

So the output look like this: console.log("Line 17 in thisFile.js")

However I would like to print the whole line of code (the previous or the next one). Since I have the line number; I would basically want to duplicate the previous/next line and surround it with quote/parenthesis and my log function.

What I would like

// a bloc of code
function aFunction(something){
    doSomething(something); // I want to log the value of something after after the doSomething function
    console.log("Line X: doSomething(something);");
    ...
}

The only questions I found which could be related to this is this one but I don't want to just log variable, but a whole line of code and I didn't find the script equivalent of duplicating a line (which is a possibility in JetBrains IDE)

LazyOne
  • 158,824
  • 45
  • 388
  • 391
JackRed
  • 1,188
  • 2
  • 12
  • 28
  • 2
    To the best of my knowledge -- you cannot look up such stuff (prev line content) from a live template. The best I can suggest is to copy the desired text into clipboard first and only then expand your live template (and use `clipboard()` in your live template (similar to how you used `lineNumber()`/`fileName()`) – LazyOne Jun 13 '19 at 10:47
  • @LazyOne yeah I tought about that before asking, but it's almost the same as copying the line, expanding an empty log command and pasting inside the quote. However, I think I'll do it, and if someone has an answer, nice otherwise i'll stay like this. Thanks – JackRed Jun 13 '19 at 11:15
  • Consider filing a Feature Request ticket to the Issue Tracker: https://youtrack.jetbrains.com/issues/IDEA -- it may get implemented one day if it gets enough votes and you provide good reasoning (although I'm sceptical abut it as it seems to be excessive/very specific case to log the actual code). – LazyOne Jun 13 '19 at 11:31
  • Thanks for the link, I almost never think of submitting ticket/request. I'm also sceptical but I guess it won't cause any harm to ask. – JackRed Jun 13 '19 at 11:39

0 Answers0