Skip to content

Commit 535a840

Browse files
authored
Merge pull request #6 from atom-ide-community/fix/vue-sfc-validation
Fix invalid languageId assigned to LSP messages preventing Vue files validation
2 parents dd22417 + 087d39d commit 535a840

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/grammar.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
};

lib/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require("path");
22
const { AutoLanguageClient } = require("atom-languageclient");
33
const { initializationOptions } = require("./config");
4+
const { renameGrammarForScopeName } = require("./grammar");
45

56
class VueLanguageClient extends AutoLanguageClient {
67
getGrammarScopes() {
@@ -20,6 +21,10 @@ class VueLanguageClient extends AutoLanguageClient {
2021
);
2122
}
2223

24+
preInitialization() {
25+
renameGrammarForScopeName("text.html.vue", "Vue");
26+
}
27+
2328
getInitializeParams(projectPath, process) {
2429
// vue-language-server doesn't handle mising init options well:
2530
// https://github.com/vuejs/vetur/issues/1188

0 commit comments

Comments
 (0)