angular / vscode-ng-language-service

Angular extension for Visual Studio Code
MIT License
774 stars 116 forks source link

[feature] Optimize activation events #481

Open RKaczmarek opened 4 years ago

RKaczmarek commented 4 years ago

Is your feature request related to a problem? Please describe.

The vscode-ng-language-service is activated if html or js files are part of the workspace. This corresponds to nearly all projects.

Describe the solution you'd like

Since all angular projects depend on the angular.json file, this file could be used as an activation point and prevent starting the extension in non angular workspaces.

"activationEvents": [
    "workspaceContains:**/angular.json"
]

Describe alternatives you've considered

Additional context

The solution should be discussed. I don't know, if it conflicts with other concepts like Angular Elements...

kyliau commented 4 years ago

@RKaczmarek Thank you for the feedback! We've thought about this before, but from my discussion with several Angular users in the past, not everyone who uses the framework also uses the CLI. Currently, we already try to detect whether a project is Angular by looking at @angular/core in node_modules. If a project is not Angular based on this detection logic, the extension stops doing any work. Are you aware of any downsides with the current approach?

RKaczmarek commented 4 years ago

@kyliau

Negative, no downtime, but...

Sounds like there's an ez way to get both solutions combined.

Since the activation events are joined with an "or" it should be possible to use

"activationEvents": [
    "workspaceContains:**/angular.json",
    "WorkspaceContains:node_modules/@angular/core/index.ts"
]

Or any file you suggest as definently existing.

So, if using cli the angular.json exists and as fallback the VSC looks for the node module.

kyliau commented 4 years ago

@RKaczmarek that sounds like a good idea. I guess the only downside is that when users open a file or a subdirectory that does not contain the angular.json or @angular/core/index.d.ts file then the extension would not be activated, which is fine, I think?

RKaczmarek commented 4 years ago

@kyliau yes, should be.

That makes the angular project check in the angular language server obsolete.