-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
016203c
commit c7d009d
Showing
14 changed files
with
421 additions
and
973 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import vscode, {CancellationToken, ProviderResult, SemanticTokens, TextDocument} from "vscode" | ||
import * as fs from "fs"; | ||
|
||
// import * as fs from "fs"; | ||
|
||
interface IParsedToken { | ||
line: number; | ||
startCharacter: number; | ||
length: number; | ||
tokenType: number; | ||
tokenModifier?: number | ||
} | ||
|
||
const tokenTypes = new Map<string, number>() | ||
const tokenModifiers = new Map<string, number>() | ||
export const legendIcB = (function () { | ||
const tokenTypesLegend = [ | ||
"parameter", "keyword", "enumMember", | ||
"property", "function", | ||
"variable", "label" | ||
] | ||
tokenTypesLegend.forEach((tokenType, index) => tokenTypes.set(tokenType, index)) | ||
|
||
const tokenModifiersLegend = [ | ||
"declaration", "readonly" | ||
] | ||
tokenModifiersLegend.forEach((tokenModifier, index) => tokenModifiers.set(tokenModifier, index)) | ||
|
||
return new vscode.SemanticTokensLegend(tokenTypesLegend, tokenModifiersLegend) | ||
})() | ||
|
||
export class IcBSemanticTokensProvider implements vscode.DocumentSemanticTokensProvider { | ||
|
||
provideDocumentSemanticTokens(document: TextDocument, token: CancellationToken): ProviderResult<SemanticTokens> { | ||
const allTokens = this._parseText(document.getText()) | ||
const builder = new vscode.SemanticTokensBuilder(legendIcB) | ||
allTokens.forEach((token) => { | ||
builder.push( | ||
token.line, token.startCharacter, token.length, | ||
token.tokenType, | ||
) | ||
}) | ||
return builder.build() | ||
} | ||
|
||
_parseText(text: string): IParsedToken[] { | ||
try { | ||
let r: IParsedToken[] = [] | ||
const lines = text.split(/\r\n|\r|\n/) | ||
const vars: string[] = [] | ||
const keywords: string[] = [] | ||
const constants: string[] = [] | ||
|
||
lines.forEach((line) => { | ||
let match | ||
try { | ||
let re = /\b(var|alias)\s+([\w\d]+).*/ | ||
if (re.test(line)) { | ||
match = re.exec(line) | ||
vars.push(match[2]) | ||
} | ||
re = /\b(const|define)\s+([\w\d]+).*/ | ||
if (re.test(line)) { | ||
match = re.exec(line) | ||
constants.push(match[2]) | ||
} | ||
re = /([\w\d]+):/ | ||
if (re.test(line)) { | ||
match = re.exec(line) | ||
keywords.push(match[1]) | ||
} | ||
} catch (e) { | ||
} | ||
}) | ||
console.table(vars) | ||
fs.writeFileSync('C:\\Projects\\IC\\vscode-stationeers-ic10\\core\\Test.json',JSON.stringify(vars)) | ||
|
||
lines.forEach((line, index) => { | ||
try { | ||
for (let value of vars) { | ||
r = this.pushToken(value, line, index, 0, null, r) | ||
} | ||
for (let value of keywords) { | ||
r = this.pushToken(value, line, index, 1, null, r) | ||
} | ||
for (let value of constants) { | ||
r = this.pushToken(value, line, index, 2, 1, r) | ||
} | ||
} catch (e) { | ||
} | ||
}) | ||
return r | ||
} catch (e) { | ||
} | ||
return [] | ||
} | ||
|
||
pushToken(search, line, index, tokenType, tokenModifier, out: IParsedToken[]) { | ||
const find = new RegExp("\\b" + search + "\\b", "y") | ||
try { | ||
for (let i = 0; i < line.length; i++) { | ||
if (line[i] == "#") { | ||
break | ||
} | ||
find.lastIndex = i | ||
const match = find.exec(line) | ||
if (match && match[0] == search) { | ||
const a: IParsedToken = { | ||
line: index, | ||
startCharacter: match.index, | ||
length: search.length, | ||
tokenType: tokenType, | ||
} | ||
if (tokenModifier !== null) { | ||
a.tokenModifier = tokenModifier | ||
} | ||
out.push(a) | ||
} | ||
} | ||
} catch (e) { | ||
} | ||
return out | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"comments": { | ||
"lineComment": "#" | ||
}, | ||
"brackets": [ | ||
[ | ||
"IF", | ||
"ENDIF" | ||
], | ||
[ | ||
"{", | ||
"}" | ||
], | ||
[ | ||
"{", | ||
"}" | ||
], | ||
[ | ||
"{", | ||
"}" | ||
], | ||
[ | ||
"[", | ||
"]" | ||
], | ||
[ | ||
"(", | ||
")" | ||
] | ||
], | ||
"autoClosingPairs": [ | ||
|
||
{ | ||
"open": "{", | ||
"close": "}" | ||
}, | ||
{ | ||
"open": "[", | ||
"close": "]" | ||
}, | ||
{ | ||
"open": "(", | ||
"close": ")" | ||
}, | ||
{ | ||
"open": "'", | ||
"close": "'", | ||
"notIn": [ | ||
"string", | ||
"comment" | ||
] | ||
}, | ||
{ | ||
"open": "\"", | ||
"close": "\"", | ||
"notIn": [ | ||
"string" | ||
] | ||
}, | ||
{ | ||
"open": "`", | ||
"close": "`", | ||
"notIn": [ | ||
"string", | ||
"comment" | ||
] | ||
}, | ||
], | ||
"autoCloseBefore": ";:.,=}])>` \n\t", | ||
"surroundingPairs": [ | ||
[ | ||
"{", | ||
"}" | ||
], | ||
[ | ||
"[", | ||
"]" | ||
], | ||
[ | ||
"(", | ||
")" | ||
], | ||
[ | ||
"'", | ||
"'" | ||
], | ||
[ | ||
"\"", | ||
"\"" | ||
], | ||
[ | ||
"`", | ||
"`" | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.