Skip to content

Commit

Permalink
fixing contextual autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Mar 17, 2023
1 parent 03624a3 commit dcd9bd3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 44 deletions.
10 changes: 9 additions & 1 deletion lib/ext-main-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ const sidebarStylo = {
},
'.cm-activeLine': {
backgroundColor: '#00aaff10'
}
},
'.cm-completionIcon-scope-module': {'&:after': {content: '"M"', 'font-style': 'italic' } },
'.cm-completionIcon-scope-class': {'&:after': {content: '"C"', 'font-style': 'italic' } },
'.cm-completionIcon-scope-other': {'&:after': {content: '"O"', 'font-style': 'italic' } },

'.cm-completionIcon-var-parameter': {'&:after': {content: '"p"'} },
'.cm-completionIcon-var-reg': {'&:after': {content: '"r"'} },
'.cm-completionIcon-var-wire': {'&:after': {content: '"w"'} },
'.cm-completionIcon-var-other': {'&:after': {content: '"o"'} }
};

const extMainTheme = EditorView.theme(sidebarStylo, {dark: true});
Expand Down
50 changes: 8 additions & 42 deletions lib/ext-waveql-lang-with.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,12 @@ const {StreamLanguage, syntaxHighlighting, HighlightStyle} = require('@codemirro
const {tags} = require('@lezer/highlight');

const get = require('./get-sig.js');
const getScopeType = require('./get-scope-type.js');
const getVarType = require('./get-var-type.js');

// waveql syntax
// https://codemirror.net/docs/ref/#language.StreamLanguage

const varTypes = {
// event: {id: 1, tag: 'variableName'},
// integer: {id: 2, tag: 'variableName'},
parameter: {id: 3, tag: 'macroName'},
// real: {id: 4, tag: 'variableName'},
// realtime: {id: 5, tag: 'variableName'},
reg: {id: 6, tag: 'atom'},
// supply0: {id: 7, tag: 'variableName'},
// supply1: {id: 8, tag: 'variableName'},
// time: {id: 9, tag: 'variableName'},
// tri: {id: 10, tag: 'variableName'},
// triand: {id: 11, tag: 'variableName'},
// trior: {id: 12, tag: 'variableName'},
// trireg: {id: 13, tag: 'variableName'},
// tri0: {id: 14, tag: 'variableName'},
// tri1: {id: 15, tag: 'variableName'},
// wand: {id: 16, tag: 'variableName'},
wire: {id: 17, tag: 'bool'}
// wor: {id: 18, tag: 'variableName'}
};

const scopeTypes = {
module: {id: 0, tag: 'meta'},
// task: {id: 1, tag: 'namespace'},
// function: {id: 2, tag: 'namespace'},
// begin: {id: 3, tag: 'namespace'},
// fork: {id: 4, tag: 'namespace'},
// extra scopes from Verilator
// generate: {id: 5, tag: 'namespace'},
// struct: {id: 6, tag: 'namespace'},
// union: {id: 7, tag: 'namespace'},
class: {id: 8, tag: 'className'}
// interface: {id: 9, tag: 'namespace'},
// package: {id: 10, tag: 'namespace'},
// program: {id: 11, tag: 'namespace'}
};


// https://github.com/lezer-parser/highlight/blob/main/src/highlight.ts

Expand Down Expand Up @@ -82,7 +47,7 @@ const waveQlLang = wires => ({

if (stream.eatSpace()) { return null; }

mat = stream.match(/^#/); if (mat) { stream.skipToEnd(); return 'comment'; }
mat = stream.match(/^\/\//); if (mat) { stream.skipToEnd(); return 'comment'; }

mat = stream.match(/^@\d+[munpf]*s(\.\w+)*(\s+|$)/); if (mat) { return 'unit'; }

Expand All @@ -107,21 +72,22 @@ const waveQlLang = wires => ({
if (ero) {
if (ero.kind === 'scope') {
stt.path = newPath;
return (scopeTypes[ero.type] || {tag: 'namespace'}).tag;
return (getScopeType(ero.type)).tag;
}
if (ero.kind === 'var') {
// stt.varWidth = ero.size;
return (varTypes[ero.type] || {tag: 'variableName'}).tag;
return (getVarType(ero.type)).tag;
}
}
return 'comment';
}
},
languageData: {
commentTokens: {line: '//'}
}
});




const extWaveqlLangWith = (wires) => {
// console.log(wires);
return [
Expand Down
22 changes: 22 additions & 0 deletions lib/get-scope-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const getScopeType = (key) => {
const lut = {
module: {id: 0, tag: 'meta', icon: 'module'},
// task: {id: 1, tag: 'namespace'},
// function: {id: 2, tag: 'namespace'},
// begin: {id: 3, tag: 'namespace'},
// fork: {id: 4, tag: 'namespace'},
// extra scopes from Verilator
// generate: {id: 5, tag: 'namespace'},
// struct: {id: 6, tag: 'namespace'},
// union: {id: 7, tag: 'namespace'},
class: {id: 8, tag: 'className', icon: 'class'}
// interface: {id: 9, tag: 'namespace'},
// package: {id: 10, tag: 'namespace'},
// program: {id: 11, tag: 'namespace'}
};
return lut[key] || {tag: 'namespace', icon: 'other'};
};

module.exports = getScopeType;
27 changes: 27 additions & 0 deletions lib/get-var-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const getVarType = (key) => {
const lut = {
// event: {id: 1, tag: 'variableName'},
// integer: {id: 2, tag: 'variableName'},
parameter: {id: 3, tag: 'macroName', icon: 'parameter'},
// real: {id: 4, tag: 'variableName'},
// realtime: {id: 5, tag: 'variableName'},
reg: {id: 6, tag: 'atom', icon: 'reg'},
// supply0: {id: 7, tag: 'variableName'},
// supply1: {id: 8, tag: 'variableName'},
// time: {id: 9, tag: 'variableName'},
// tri: {id: 10, tag: 'variableName'},
// triand: {id: 11, tag: 'variableName'},
// trior: {id: 12, tag: 'variableName'},
// trireg: {id: 13, tag: 'variableName'},
// tri0: {id: 14, tag: 'variableName'},
// tri1: {id: 15, tag: 'variableName'},
// wand: {id: 16, tag: 'variableName'},
wire: {id: 17, tag: 'bool', icon: 'wire'}
// wor: {id: 18, tag: 'variableName'}
};
return lut[key] || {tag: 'variableName', icon: 'other'};
};

module.exports = getVarType;
2 changes: 1 addition & 1 deletion lib/waveql-parser-with.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const waveqlParserWith = wires => str => {
cols.some(col => {

// EOL comment
if (col[0] === '#') {
if (col[0] === '//') {
return true;
}

Expand Down

0 comments on commit dcd9bd3

Please sign in to comment.