vscode-auto-close-tag icon indicating copy to clipboard operation
vscode-auto-close-tag copied to clipboard

New setting proposal: onlyWithinQuotesOnLanguage

Open jibbers42 opened this issue 7 years ago • 5 comments

Working in a language like typescript causes false tag closes when coding generics. A new setting that restricts closes to only when typing in a quoted string would allow users to keep this feature enabled with far less false closes. Coding angular inline templates is an example of where this might be used.

"auto-close-tag.onlyWithinQuotesOnLanguage": [
    "typescript"
]

Edit: I'm not sure what information the extension environment provides. Maybe there is a better way, such as knowing you're in a generic - or something similar.

jibbers42 avatar Apr 24 '17 09:04 jibbers42

In a quoted string? Could you please provide more details or code snippet for you scenario?

formulahendry avatar Apr 26 '17 05:04 formulahendry

Reading it again, "quoted string" is confusing wording - I just meant when typing within quotes. From angular example code...

import { Component }          from '@angular/core';

@Component({
  selector: 'my-app',
  template: `
    <h1>{{title}}</h1>
    <nav>
      <a routerLink="/dashboard" routerLinkActive="active">Dashboard</a>
      <a routerLink="/heroes" routerLinkActive="active">Heroes</a>
    </nav>
    <router-outlet></router-outlet>
  `,
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'Tour of Heroes';
}


/*
Copyright 2017 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/

It would be nice if tag auto close only happened within quotes, for example in the template section in the example code. Currently, angle brackets cause a completion when using generics within the AppComponent class (not shown).

This is a pretty minor use case since you would probably put any templates of size into a dedicated html file instead of inline as shown above. For now I've just removed typescript from the active languages setting.

jibbers42 avatar Apr 26 '17 05:04 jibbers42

@jibbers42 Only closing inside of a template literal (backtick string) in typescript may what you are looking for. Is there a case when plain single quote or double quoted strings in typescript should be considered as html to be auto-closed?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

michael-lang avatar Jul 18 '18 13:07 michael-lang

Yeah, I think that would work out well. Is that something that can enabled now?

jibbers42 avatar Jul 18 '18 20:07 jibbers42

Not that I know of, just a suggestion for what an implementation of a code change should look for, IMHO.

michael-lang avatar Jul 18 '18 21:07 michael-lang