'Is it possible to override autocompletion for the "=" character?

I work on an extension for Visual Studio Code, and would like to override some of the default behavior when editing an HTML file. When editing an HTML file in Visual Studio Code, typing the = character results in a pair of double quotes automatically being added (eg =""). In most cases, this is desired, but we'd like to have a pair of curly braces added for certain attributes (={}).

For example, with standard HTML attributes, like class and style, we want double quotes to be added, but for specific keywords we look for, we want our extension to add curly braces instead, like so:

<div class="" foo={}>

I've been looking into using the LSP for this, but the issue is that in server.ts, with each of the methods exposed on the connection object (eg connection.onCompletion, connection.onDeclaration, etc...) they get called after the pair of double quotes have been added.

Is it possible to intercept when the = character has been typed, and override the autocompletion? If so, how? And would it be using LSP, or another means?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source