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

Add TM_FILENAME_BASE snippet variable #32737

Closed
firelizzard18 opened this issue Aug 17, 2017 · 8 comments
Closed

Add TM_FILENAME_BASE snippet variable #32737

firelizzard18 opened this issue Aug 17, 2017 · 8 comments
Assignees
Labels
feature-request Request for new features or functionality good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities release-notes Release notes issues snippets verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@firelizzard18
Copy link

  • VSCode Version: Code 1.15.0 (8b95971, 2017-08-09T20:16:18.034Z)
  • OS Version: Windows_NT x64 10.0.15063
  • Extensions:
Extension Author (truncated) Version
aurelia Aur 0.3.4
nuget-reverse-package-search jes 0.1.68
vscode-nuget-package-manager jmr 1.1.4
docomment k-- 0.0.17
mssql ms- 1.1.0
csharp ms- 1.12.1
PowerShell ms- 1.4.1
debugger-for-chrome msj 3.1.8
vscode-docker Pet 0.0.16
shell-launcher Tyr 0.1.3
sort-lines Tyr 1.3.0

I am adding my own snippets to try to replace what exists in Visual Studio, as much as I can. I would like a variable such as TM_FILENAME_BASE that does not include any extensions, since that is the default class/etc name for many languages. Or better yet, the ability to apply regex replacement rules to the variables, such as ${TM_FILENAME,/^([A-Z])/\L$1/,/([a-z])([A-Z])/$1-\L$2/g,/\..*$//}:

  • TM_FILENAME - start with the filename
  • Comma separated regex replacement rules
    • /^([A-Z])/\L$1/ - if the first character is uppercase, replace it with lowercase
    • /([a-z])([A-Z])/$1-\L$2/g - replace all xY with x-y
    • /\..*$// - if the filename ends with an extension, remove it
  • Thus, MyCustomElement.html becomes my-custom-element
@jrieken jrieken added feature-request Request for new features or functionality snippets labels Aug 18, 2017
@jrieken
Copy link
Member

jrieken commented Aug 18, 2017

Or better yet, the ability to apply regex replacement rules to the variables, such as ${TM_FILENAME,/^([A-Z])/\L$1/,/([a-z])([A-Z])/$1-\L$2/g,/..*$//}:

Snippet transform is tracked here #6920. Just having FILENAME_BASE sounds like a reasonable workaround.

@jrieken jrieken added this to the August 2017 milestone Aug 18, 2017
@jrieken
Copy link
Member

jrieken commented Aug 18, 2017

@jrieken jrieken added good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities and removed new release labels Aug 18, 2017
@firelizzard18
Copy link
Author

I'll look at it this weekend.

@joelpresence
Copy link

I would love this for creating go test files. For example, if I'm in a go package a/b/c, I put my tests for package c in a/b/c/tests, its own tests package.

I have a created a snippet like the following in go.json:

{
	"Test file": {
		"prefix": "tt",
		"body": [
			"package tests",
			"",
			"import (",
			"\t\"github.com/stretchr/testify/assert\"",
			"\t. \"a/b/$1\"",
			")",
			"",
			"func Test$2(t *testing.T) {",
			"\tassert := assert.New(t)",
			"",
			"\t$0",
			"}"
		],
		"description": "Create a new test file"
	}
}

which produces

package tests

import (
	"github.com/stretchr/testify/assert"
	. "a/b/"
)

func Test(t *testing.T) {
	assert := assert.New(t)

	
}

However, if I'm in a file a/b/c/tests/foo_test.go when I expand this snippet, then the line . "a/b/" should be . "a/b/c" because these are tests for the the c package.

How do I accomplish this?

I tried using TM_DIRECTORY but it doesn't seem that I can manipulate it to remove trailing cruft. Nor can I use workspaceRoot ...

I'd really like to have access to the "parent package" but being able to manipulate the current filename with knowledge of workspace root would probably be good enough.

Will the fix mentioned in this issue support my use case (pretty common for go developers) and is there an ETA? :-)

Thanks!

@jrieken
Copy link
Member

jrieken commented Aug 24, 2017

Will the fix mentioned in this issue support my use case (pretty common for go developers) and is there an ETA? :-)

No, what you want is tracked here: #6920. This issue is about a pragmatic change to add a new variable which is the name of a file without its extension

@joelpresence
Copy link

@jrieken thanks for responding.

I had seen #6920 but it didn't seem immediately relevant when I first read it. I'll add my comments there.

@jrieken
Copy link
Member

jrieken commented Aug 25, 2017

I'll look at it this weekend.

@firelizzard18 Is this still on your radar? I don't wanna steel you thunder but I'd tackle this myself on Monday otherwise. Happy Coding

@firelizzard18
Copy link
Author

@jrieken Feel free to tackle it. Other issues have taken precedence :/

jrieken added a commit that referenced this issue Aug 28, 2017
@jrieken jrieken closed this as completed Aug 28, 2017
@jrieken jrieken changed the title More useful environment variables for snippets Add TM_FILENAME_BASE snippet variable Aug 28, 2017
@jrieken jrieken added the verification-needed Verification of issue is requested label Aug 28, 2017
@roblourens roblourens added the verified Verification succeeded label Aug 30, 2017
@jrieken jrieken added the release-notes Release notes issues label Sep 1, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities release-notes Release notes issues snippets verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants