microsoft / microsoft/vscode-textmate
syntaxes/c++.json did not work with loadGrammar method
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 678
- Forks
- 135
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 2
Description
Problem: "c++.json" file in ".\test-cases\themes\syntaxes" can not be parsed to a grammar, using the way the readme.md file says.
I called loadGrammar method to parse this grammar file, But the callback's parameter was null. First , I thought the grammar file is wrong, so I try to test it with inspect.js. It was totally fine!
Then I used the same code in inspect.js, and it worked too. Not sure if this is a bug, But the readme.md file really need to check.
this is my code according to readme.md.
var vsctm = require("vscode-textmate");
var fs = require("fs");
let grammarPaths = {
"source.js": "./config/grammars/JavaScript.tmLanguage.json",
"source.c++":"./config/grammars/c++.json",
};
let registry = new vsctm.Registry({
loadGrammar: function (scopeName) {
let path = grammarPaths[scopeName];
if (path) {
return new Promise((c,e) => {
let content = fs.readFileSync(path).toString();
let grammar = vsctm.parseRawGrammar(content,path);
console.log("RawGrammar is null",grammar==null);
c(grammar);
});
}
}
});
function test(){
registry.loadGrammar("source.js").then(grammar => {
// grammar is not null
console.log("source.js",grammar);
});
registry.loadGrammar("source.c++").then(grammar => {
// grammar is null , I do not know why...
console.log("source.c++",grammar);
});
}
test()
this is the code in inspect.js
var GRAMMAR_PATHS = ["E:\\codeparser\\vscode-textmate-master\\test-cases\\themes\\syntaxes\\c++.json"]
var FILE_PATH = "E:\\codeparser\\vscode-textmate-master\\benchmark\\xxx.cpp"
// process.env["VSCODE_TEXTMATE_DEBUG"] = true;
var main = require("vscode-textmate");
var fs = require("fs");
var Registry = main.Registry;
var registry = new Registry();
var grammarPromise = null;
for (let path of GRAMMAR_PATHS) {
var content = fs.readFileSync(path).toString();
var rawGrammar = main.parseRawGrammar(content, path);
var g = registry.addGrammar(rawGrammar);
grammarPromise = grammarPromise || g;
}
grammarPromise.then(grammar => {
console.log("source.c++",grammar)// grammar is not null !
}
I am sure the I used the same "c++.json" file .
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported difference between Registry.loadGrammar and the inspect.js path using test-cases/themes/syntaxes/c++.json. Compare the README example with inspect.js and trace the loadGrammar callback for source.c++; the work is done when the cause of the null grammar is identified and the README or behavior is corrected and verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100