Using Map objects instead of indexable types

This commit is contained in:
Noah Santschi-Cooney 2018-07-04 00:16:22 +01:00
parent 34e6d14ec9
commit dbad626af9
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
3 changed files with 36 additions and 37 deletions

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 944 KiB

Before After
Before After

View file

@ -15,41 +15,40 @@ const filters = [
/Could not process include directive for header name:/ /Could not process include directive for header name:/
] ]
const files: {[uri: string]: number} = {} const files = new Map<string, number>()
export const ext = { export const ext = new Map([
'.fsh': 'frag', ['.fsh', 'frag'],
'.gsh': 'geom', ['.gsh', 'geom'],
'.vsh': 'vert', ['.vsh', 'vert'],
//'.glsl': 'frag' //excluding non standard files, need to be treated differently ])
}
const tokens: {[key: string]: string} = { const tokens = new Map([
'SEMICOLON': ';', ['SEMICOLON', ';'],
'COMMA': ',', ['COMMA', ','],
'COLON': ':', ['COLON', ':'],
'EQUAL': '=', ['EQUAL', '='],
'LEFT_PAREN': '(', ['LEFT_PAREN', '('],
'RIGHT_PAREN': ')', ['RIGHT_PAREN', ')'],
'DOT': '.', ['DOT', '.'],
'BANG': '!', ['BANG', '!'],
'DASH': '-', ['DASH', '-'],
'TILDE': '~', ['TILDE', '~'],
'PLUS': '+', ['PLUS', '+'],
'STAR': '*', ['STAR', '*'],
'SLASH': '/', ['SLASH', '/'],
'PERCENT': '%', ['PERCENT', '%'],
'LEFT_ANGEL': '<', ['LEFT_ANGEL', '<'],
'RIGHT_ANGEL': '>', ['RIGHT_ANGEL', '>'],
'VERICAL_BAR': '|', ['VERICAL_BAR', '|'],
'CARET': '^', ['CARET', '^'],
'AMPERSAND': '&', ['AMPERSAND', '&'],
'QUESTION': '?', ['QUESTION', '?'],
'LEFT_BRACKET': '[', ['[LEFT_BRACKET', '['],
'RIGHT_BRACKET': ']', ['RIGHT_BRACKET', ']'],
'LEFT_BRACE': '{', ['LEFT_BRACE', '{'],
'RIGHT_BRACE': '}' ['RIGHT_BRACE', '}'],
} ])
// TODO exclude exts not in ext // TODO exclude exts not in ext
export function preprocess(lines: string[], docURI: string, topLevel: boolean, incStack: string[]) { export function preprocess(lines: string[], docURI: string, topLevel: boolean, incStack: string[]) {
@ -88,7 +87,6 @@ export function preprocess(lines: string[], docURI: string, topLevel: boolean, i
if (!topLevel) return if (!topLevel) return
//console.log(lines.join('\n'))
try { try {
lint(docURI, lines, includes) lint(docURI, lines, includes)
} catch (e) { } catch (e) {
@ -139,12 +137,14 @@ function lint(uri: string, lines: string[], includes: {lineNum: number, match: R
message: replaceWord(msg), message: replaceWord(msg),
source: 'mc-glsl' source: 'mc-glsl'
} }
//diagnostics[file ? uri : file].push(diag) diagnostics[file ? uri : file].push(diag)
}) })
daigsArray(diagnostics).forEach(d => connection.sendDiagnostics({uri: d.uri, diagnostics: d.diag})) daigsArray(diagnostics).forEach(d => connection.sendDiagnostics({uri: d.uri, diagnostics: d.diag}))
} }
const replaceWord = (msg: string) => Object.entries(tokens).reduce((acc, [key, value]) => acc.replace(key, value), msg)
const daigsArray = (diags: {[uri: string]: Diagnostic[]}) => Object.keys(diags).map(uri => ({uri: 'file://' + uri, diag: diags[uri]})) const daigsArray = (diags: {[uri: string]: Diagnostic[]}) => Object.keys(diags).map(uri => ({uri: 'file://' + uri, diag: diags[uri]}))
const filterMatches = (output: string) => output const filterMatches = (output: string) => output
@ -153,8 +153,6 @@ const filterMatches = (output: string) => output
.map(s => s.match(reDiag)) .map(s => s.match(reDiag))
.filter(match => match && match.length === 5) .filter(match => match && match.length === 5)
const replaceWord = (msg: string) => Object.entries(tokens).reduce((acc, [key, value]) => acc.replace(key, value), msg)
function calcRange(lineNum: number, uri: string): Range { function calcRange(lineNum: number, uri: string): Range {
const lines = documents.get('file://' + uri).getText().split('\n') const lines = documents.get('file://' + uri).getText().split('\n')
const line = lines[lineNum] const line = lines[lineNum]

View file

@ -33,6 +33,7 @@ documents.onDidSave((event) => onEvent(event.document))
//documents.onDidChangeContent(onEvent) //documents.onDidChangeContent(onEvent)
function onEvent(document: TextDocument) { function onEvent(document: TextDocument) {
if (!ext.has(extname(document.uri))) return
preprocess(document.getText().split('\n'), formatURI(document.uri), true, [document.uri.replace(/^file:\/\//, '')]) preprocess(document.getText().split('\n'), formatURI(document.uri), true, [document.uri.replace(/^file:\/\//, '')])
} }