File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ function updateOpenEditors ( oldGrammar , newGrammar ) {
2
+ const openEditors = atom . workspace . getTextEditors ( ) ;
3
+ openEditors . forEach ( editor => {
4
+ const editorGrammar = editor . getGrammar ( ) ;
5
+
6
+ const hasOldGrammar = editorGrammar . name === oldGrammar . name ;
7
+ if ( hasOldGrammar ) {
8
+ editor . setGrammar ( newGrammar ) ;
9
+ }
10
+ } ) ;
11
+ }
12
+
13
+ function renameGrammarForScopeName ( scopeName , newName ) {
14
+ const currentGrammar = atom . grammars . grammarForScopeName ( scopeName ) ;
15
+
16
+ if ( currentGrammar ) {
17
+ atom . grammars . readGrammar ( currentGrammar . path , ( error , grammarRenamed ) => {
18
+ if ( error ) {
19
+ console . error ( "Failed to read grammar to rename" , error ) ;
20
+ return ;
21
+ }
22
+
23
+ grammarRenamed . name = newName ;
24
+
25
+ atom . grammars . removeGrammarForScopeName ( scopeName ) ;
26
+ atom . grammars . addGrammar ( grammarRenamed ) ;
27
+
28
+ updateOpenEditors ( currentGrammar , grammarRenamed ) ;
29
+
30
+ console . log (
31
+ `Grammar for scope ${ scopeName } renamed from "${ currentGrammar . name } " to "${ grammarRenamed . name } "`
32
+ ) ;
33
+ } ) ;
34
+ }
35
+ }
36
+
37
+ module . exports = {
38
+ renameGrammarForScopeName
39
+ } ;
Original file line number Diff line number Diff line change 1
1
const path = require ( "path" ) ;
2
2
const { AutoLanguageClient } = require ( "atom-languageclient" ) ;
3
3
const { initializationOptions } = require ( "./config" ) ;
4
+ const { renameGrammarForScopeName } = require ( "./grammar" ) ;
4
5
5
6
class VueLanguageClient extends AutoLanguageClient {
6
7
getGrammarScopes ( ) {
@@ -20,6 +21,10 @@ class VueLanguageClient extends AutoLanguageClient {
20
21
) ;
21
22
}
22
23
24
+ preInitialization ( ) {
25
+ renameGrammarForScopeName ( "text.html.vue" , "Vue" ) ;
26
+ }
27
+
23
28
getInitializeParams ( projectPath , process ) {
24
29
// vue-language-server doesn't handle mising init options well:
25
30
// https://github.com/vuejs/vetur/issues/1188
You can’t perform that action at this time.
0 commit comments