formulahendry / vscode-auto-close-tag

Auto Close Tag for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag
MIT License
179 stars 53 forks source link

New setting proposal: onlyWithinQuotesOnLanguage #37

Open jibbers42 opened 7 years ago

jibbers42 commented 7 years ago

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.

formulahendry commented 7 years ago

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

jibbers42 commented 7 years ago

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.

michael-lang commented 6 years ago

@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

jibbers42 commented 6 years ago

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

michael-lang commented 6 years ago

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