-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
Support for Emmet preferences and syntaxProfiles #7926
Support for Emmet preferences and syntaxProfiles #7926
Conversation
Hi @mrmlnc, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
@mrmlnc Thanks for the well documented Pull Request. I've looked into the emmet preferences API and I don't fully understand your explanation of why you did not use If |
Now I see, set throws an exception, when the setting is not defined... Object.keys(prefs).forEach(function(k) {
var v = prefs[k];
if (!(k in defaults)) {
throw new Error('Property "' + k + '" is not defined. You should define it first with `define` method of current module');
} |
OK, I now catch the exception when the preferences isn't defined yet and then I define the setting. I also use the approach to merge in the editor settings before an emmet operation and then I reset them after. This simplifies the implementation. Please review. |
@egamma, unfortunately, we are both wrong. My versionMethod Your versionMore likely, most users will not use the Emmet preferences and syntaxProfiles. Thus, the setting and resetting of settings when each action is not the best idea (deoptimization?). For example: My proposalUse the methods P.S.: Sorry for my English. |
I made some small changes so that there is no overhead when the user doesn't have emmet preferences. I must say I like the simplicity of the current code compared to the original PR. However, if the simple code is not correct, then it needs to be fixed 😄. I'll also implement a solution that uses your approach and then we can compare. OK? |
@egamma, good idea.
The thing is that i originally thought to allow users to change all settings. But looking at the code of Emmet i realized that they are meaningless. My vision settings for Emmet: mrmlnc/vscode/../emmetActions.ts |
@mrmlnc please tell me how to execute a command "wrap abbreviation" on hotkey? |
[{
"key": "ctrl+alt+w",
"command": "editor.emmet.action.wrapWithAbbreviation",
"when": "editorTextFocus"
}] |
DisclaimerI don't know how much is a correct test, but the results are interesting. Tests
ResultsCurrent version (first run ~300ms)Current version witn Emmet bundle by Gulp (first run ~300ms)My version (code) (first run ~150ms)My version with Emmet bundle by Gulp (first run ~150ms) |
@egamma i just moved https://gist.github.com/mrmlnc/3345b7d2a709e125d517e91ad1b9ca6f#file-emmet-ts-L42-L44 And settings apply when they are changed. https://gist.github.com/mrmlnc/3345b7d2a709e125d517e91ad1b9ca6f#file-emmet-ts-L39-L40 |
The EmmetAction constructor is called during startup. This means your version activates emmet on startup, which is what we want to avoid we do not want to add to the startup time. This is why we load emmet on the first tab key.
Keep in mind that the Action constructor is called for each action, this means you register a listener for each action (which I think there are now 17). This also means you update the preferences multiple times.
|
@egamma, you are right. |
@mrmlnc thanks for the investigation anyways, it shows that the bundling of emmet is not a win. |
Excuse
Sorry, but this is my first experience with the TypeScript. If everything is very bad, then let me know about this or add the proposed PR manually with correct code.
Why?
In the previous PR was added support Emmet for Sass and Stylus (#7887). That's cool, but Stylus has free syntax. For example:
By default, Emmet has the syntax:
position absolute
orfont-size 14px
. Using the Emmet preferences you can fix this. This PR adds support for Emmet preferences and syntaxProfiles.Demo
Emmet preferences:
Emmet syntaxProfiles
Why you do not use
emmet.preferences.load()
oremmet.loadPreferences()
Unfortunately, both methods work only with
emmet.preferences.set()
and not provide access toemmet.preferences.define()
that there is a need for rules that are not declared by default.Question for developers
I'm not sure that the code in the constructor is correct. I couldn't think of a better way for access to Emmet one time.