Skip to content

Double Hash (##) Trigger #1220

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

Closed
theznerd opened this issue Mar 1, 2018 · 10 comments · Fixed by #3023
Closed

Double Hash (##) Trigger #1220

theznerd opened this issue Mar 1, 2018 · 10 comments · Fixed by #3023
Labels

Comments

@theznerd
Copy link

theznerd commented Mar 1, 2018

Is there a way to disable the double hash trigger that adds single line comment blocks inside of functions aside from forking and removing the trigger myself? I'd prefer to just use the comment block "<#" trigger and leave my ability to comment out sections of my code using multiple hash marks (e.g. ###### BEGIN USER EDITABLE SECTION ######)

@Geogboe
Copy link

Geogboe commented Mar 1, 2018

I just noticed this myself. I actually just discovered it accidentally but can't find ANY docs pertaining to it. It's not even listed in the snippet reference: https://github.com/PowerShell/vscode-powershell/blob/master/snippets/PowerShell.json#L536-L555

No sure if this is happening for anyone else but, for me, it only happens if I use a double hash ( ## ) either at the FIRST line after a function declaration or at the FIRST line above a function declaration:

##############################
#.SYNOPSIS
#Short description
#
#.DESCRIPTION
#Long description
#
#.EXAMPLE
#An example
#
#.NOTES
#General notes
##############################

function My-Function  {
##############################
#.SYNOPSIS
#
#
#.DESCRIPTION
#Long description
#
#.EXAMPLE
#An example
#
#.NOTES
#General notes
##############################
    [CmdletBinding()]
    param (
        
    )
    
    begin {
    }
    
    process {
    }
    
    end {
    }
}

There tends to also be a slight delay sometimes where, if I start typing, the snippet isn't automatically injected.

So maybe a quick workaround is to make sure you create a space between your comment and the function declaration.

@theznerd
Copy link
Author

theznerd commented Mar 1, 2018

Seems to happen at the last line of a function too... If I create my function with three empty lines, I can successfully put the double-hash in the middle one without the trigger taking place. Will be an alright workaround for now.

The "offending" code is located in at line 117 of HelpCompletion.ts - at least this is where the trigger is defined.

https://github.com/PowerShell/vscode-powershell/blob/master/src/features/HelpCompletion.ts#L117

@Geogboe
Copy link

Geogboe commented Mar 1, 2018

@theznerd Good find! I guess it's not considered a snippet then.

@rjmholt rjmholt added Issue-Bug A bug to squash. Issue-Enhancement A feature request (enhancement). Issue-Performance Something's slow. labels Mar 21, 2018
@TylerLeonhardt
Copy link
Member

Yeah so this is more powerful than a snippet. It will scan your function and add parameter comments and such to the help.

You're right, we need to document this better. Feel free to open an issue to write a doc (or contribute if you'd like! 😃)

Just an FYI...
Right now there's a bug in the <# help comments generation. See #1228

We're considering doing some abstractions to allow folks to register their own Editor completions - this will also give folks the ability to remove built in ones so if you like <# vs ## you can remove the one you don't want.

Thanks for filing this!

@TylerLeonhardt TylerLeonhardt added Area-Snippets and removed Issue-Performance Something's slow. labels Mar 22, 2018
@samusstrike
Copy link

samusstrike commented Sep 25, 2020

The issue I have with this is that it is occurring in non-PowerShell files. The "snippet" (for lack of better term) is triggering within a JavaScript file.

Could you please limit the triggering of this (and other PowerShell specific actions) to only PowerShell specific file types?

VSCode PowerShell extension version: v2020.6.0

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Sep 25, 2020
@TylerLeonhardt
Copy link
Member

Can you share a JS file snippet of where you're seeing this?

@TylerLeonhardt TylerLeonhardt removed the Needs: Maintainer Attention Maintainer attention needed! label Sep 25, 2020
@samusstrike
Copy link

samusstrike commented Oct 8, 2020

Sorry for the delay; too much work ;)

Here is the snippet which I'm able to reproduce the issue. The behavior is variable depending on where comment blocks or perhaps any other lines of code are. I provided comments in the code snippet to indicate where I was able to type ## and repro the issue. There are other permutations, but this will hopefully give you what you need.

You must have this code in a persisted file rather than an untitled window.

function foo() {
	//asdf
	//Add 2 hashes above this comment, below this comment, within the console.log, anywhere between the main function defintion and the first sub-function definition. Having two comments before the function causes the issue not to occur. Must have an empty line either before this comment or after.

	console.log("")

	function bar() {

		//Happens here too above or on the same line as this comment, but not below. But if you add a comment above or below, the behavior changes.

	}

	//No issue

	console.log("##")


	//This function definition does not need to be here for the issue to occur.

	function baz() {

	}
}

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Oct 8, 2020
@SydneyhSmith
Copy link
Collaborator

Thanks @samusstrike we are having a bit of trouble reproducing this...it would be great to see a screenshot or GIF of your whole vscode screen...in particular it would be great to confirm the file type that it is opened as in vscode--thanks!

@SydneyhSmith SydneyhSmith added Needs-Repro-Info and removed Needs: Maintainer Attention Maintainer attention needed! labels Oct 13, 2020
@samusstrike
Copy link

samusstrike commented Oct 21, 2020

Here are the steps to reproduce with more specificity. One thing to keep in mind is that you have to wait until the PowerShell extension has loaded to some degree so that it will start triggering the "## snippet". If you have VSCode open already and have opened a PowerShell file type for some time, then it should trigger right away.

Steps:

  1. Open VSCode
  2. Open a JavaScript file with the code snippet (or create a new JavaScript file with the code snippet and save it to the file system)
  3. Open a new tab and format it as PowerShell (to get the PowerShell extension to trigger the startup)
  4. In the JavaScript file, type ## at the top of the function (as shown in the screenshots)
  5. At this point, I had to wait about 5 minutes and 10 seconds for the issue to then trigger. Once triggered, it will occur repeatedly by typing ##

Startup after completing step 4:

StartingPowerShellExtension

Issue Illustration:

DoubleHashSnippetIssue

The JavaScript snippet was listed in a previous comment. Here it is again to keep the entire repro in one place:

function foo() {
	//asdf
	//Add 2 hashes above this comment, below this comment, within the console.log, anywhere between the main function defintion and the first sub-function definition. Having two comments before the function causes the issue not to occur. Must have an empty line either before this comment or after.

	console.log("")

	function bar() {

		//Happens here too above or on the same line as this comment, but not below. But if you add a comment above or below, the behavior changes.

	}

	//No issue

	console.log("##")


	//This function definition does not need to be here for the issue to occur.

	function baz() {

	}
}

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Oct 21, 2020
@SydneyhSmith
Copy link
Collaborator

Thanks @samusstrike for the detailed info, we were able to get this to reproduce. It looks like we do not have a filter in place for this feature to only run on PowerShell files. We are currently looking into the fix--thanks!

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

Successfully merging a pull request may close this issue.

6 participants