From e507baf9dfb3b35fc7a593176ed4df4e1fada818 Mon Sep 17 00:00:00 2001 From: "Scott M. Wyant" <29161635+scottmwyant@users.noreply.github.com> Date: Sat, 6 Feb 2021 13:05:25 -0500 Subject: [PATCH 1/6] chore(cd.yml): Make deploy job conditional The workflow was being triggered when any tag was created, and even when a new branch was created. Now, it will be skipped when the payload of the create event is a branch, or if the tag doesn't start with 'refs/tags/v'. --- .github/workflows/cd.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index fe84be6..35f9d7a 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,8 +1,5 @@ name: CD -on: - create: - tag: - - v\d+\.\d+\.\d+(\.[\w\d-]+)? +on: create env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VSCE_PAT: ${{secrets.VSCE_PAT}} @@ -10,9 +7,10 @@ env: jobs: deploy: + if: (github.event.ref_type == 'tag') && (startsWith(github.ref, 'refs/tags/v')) runs-on: ubuntu-latest steps: - + - name: Checkout source code uses: actions/checkout@v2 From fc30bf463c550b31db9031889c6b7c487a232ddb Mon Sep 17 00:00:00 2001 From: "Scott M. Wyant" <29161635+scottmwyant@users.noreply.github.com> Date: Thu, 4 Feb 2021 13:27:39 -0500 Subject: [PATCH 2/6] fix(package.json): Support .ssb and .lib files --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a039a3..95e5e94 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ ".h", ".hnc", ".knc", + ".lib", ".maz", ".min", ".mpf", @@ -82,6 +83,7 @@ ".sbc", ".sbp", ".spf", + ".ssb", ".t", ".tap", ".xpi" @@ -145,4 +147,4 @@ "@types/vscode": "^1.46.0", "typescript": "^3.8.0" } -} \ No newline at end of file +} From 5cec370ed8ca1c853032695d841141bee400b07e Mon Sep 17 00:00:00 2001 From: "Scott M. Wyant" <29161635+scottmwyant@users.noreply.github.com> Date: Fri, 5 Feb 2021 19:54:55 -0500 Subject: [PATCH 3/6] chore(gcode.tmLanguage.json): Format document, whitespace --- src/grammar/gcode.tmLanguage.json | 556 +++++++++++++++--------------- 1 file changed, 278 insertions(+), 278 deletions(-) diff --git a/src/grammar/gcode.tmLanguage.json b/src/grammar/gcode.tmLanguage.json index 6282a3f..285c02a 100644 --- a/src/grammar/gcode.tmLanguage.json +++ b/src/grammar/gcode.tmLanguage.json @@ -1,295 +1,295 @@ { - "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", - "name": "gcode", - "scopeName": "source.gcode", - "foldingStartMarker": "^O([A-Z0-9]{1,4})(?=\\s|$|\\()", - "foldingStopMarker": "^RTS$", - "patterns": [ - { - "include": "#sub-programs" - }, - { - "include": "#operators" - }, - { - "include": "#address-alphanumeric" - }, - { - "include": "#address-integer" - }, - { - "include": "#address-decimal" - }, - { - "include": "#variables" - }, - { - "include": "#comments" - } - ], - "repository": { - "operators": { - "patterns": [ - { - "name": "operator.goto.gcode", - "match": "^GOTO (N\\d{1,5}|N[A-Z][A-Z0-9]{0,4})$" - }, - { - "name": "operator.if.gcode", - "match": "IF\\[.*\\](N\\d{1,5}|N[A-Z][A-Z0-9]{0,4})" - }, - { - "name": "operator.comparison.gcode", - "match": " (LT|LE|EQ|NE|GE|GT) " - }, - { - "name": "operator.logical.gcode", - "match": " (AND|OR|EOR|NOT) " - }, - { - "name": "operator.arithmetic.gcode", - "match": "([\\+\\-\\*\\/])" - }, - { - "name": "operator.other.gcode", - "match": "(SIN|COS|TAN|ATAN|ATAN2|SQRT|ABS|BIN|BCD|ROUND|FIX|DROUND|DFIX|DFUP|MOD)\\[(.*)\\]", - "captures": { - "2": { - "patterns": [ - { - "include": "#variables" - } - ] - } + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "gcode", + "scopeName": "source.gcode", + "foldingStartMarker": "^O([A-Z0-9]{1,4})(?=\\s|$|\\()", + "foldingStopMarker": "^RTS$", + "patterns": [ + { + "include": "#sub-programs" + }, + { + "include": "#operators" + }, + { + "include": "#address-alphanumeric" + }, + { + "include": "#address-integer" + }, + { + "include": "#address-decimal" + }, + { + "include": "#variables" + }, + { + "include": "#comments" + } + ], + "repository": { + "operators": { + "patterns": [ + { + "name": "operator.goto.gcode", + "match": "^GOTO (N\\d{1,5}|N[A-Z][A-Z0-9]{0,4})$" + }, + { + "name": "operator.if.gcode", + "match": "IF\\[.*\\](N\\d{1,5}|N[A-Z][A-Z0-9]{0,4})" + }, + { + "name": "operator.comparison.gcode", + "match": " (LT|LE|EQ|NE|GE|GT) " + }, + { + "name": "operator.logical.gcode", + "match": " (AND|OR|EOR|NOT) " + }, + { + "name": "operator.arithmetic.gcode", + "match": "([\\+\\-\\*\\/])" + }, + { + "name": "operator.other.gcode", + "match": "(SIN|COS|TAN|ATAN|ATAN2|SQRT|ABS|BIN|BCD|ROUND|FIX|DROUND|DFIX|DFUP|MOD)\\[(.*)\\]", + "captures": { + "2": { + "patterns": [ + { + "include": "#variables" + } + ] } } - ] - }, - "sub-programs": { - "comment": "Keywords related to sub programs", - "patterns": [ - { - "name": "keyword.subcall.gcode", - "match": "CALL O([A-Z0-9]{1,4}).*" - }, - { - "name": "keyword.sub.gcode", - "match": "^O([A-Z0-9]{1,4})(?=\\s|$|\\()" - }, - { - "name": "keyword.subend.gcode", - "match": "^RTS$" - } - ] - }, - "variables": { - "comment": "Local, common, and system variables", - "patterns": [ - { - "name": "var.local.okuma.gcode", - "match": "([ABCDEFGHIJKLMPQRSTUWXYZ][A-Z][A-Z0-9]{0,2})" - }, - { - "name": "var.common.okuma.gcode", - "match": "VC(\\d{1,4}|\\[(\\d{1,4}|VC\\d{1,4}|[A-Z]{2}[A-Z0-9]{0,2})\\])" - }, - { - "name": "var.system.okuma.gcode", - "match": "V[A-Z][A-Z0-9]{1,4}(\\[.*\\])?" - }, - { - "name": "var.local.fanuc.gcode", - "match": "\\#([1-9]|[12][0-9]|3[0-3])(?!\\d)" - }, - { - "name": "var.common.fanuc.gcode", - "match": "\\#([1-9][0-9]{2}})" - }, - { - "name": "var.system.fanuc.gcode", - "match": "\\#([1-9][0-9]{3})(?!\\d)" - } - ] - }, - "address-alphanumeric": { - "comment": "A single letter followed by one or more alphanumeric characters", - "patterns": [ - { - "name": "word.d.gcode", - "match": "D([ABC]|\\d+)" - }, - { - "name": "word.h.gcode", - "match": "H([ABC]|\\d+)" - }, - { - "name": "word.n.gcode", - "match": "^(N)(\\d{1,5}|[A-Z][A-Z0-9]{0,4})(?=\\s|$|\\()", - "captures": { - "0": { - "name": "replace.n" - } + } + ] + }, + "sub-programs": { + "comment": "Keywords related to sub programs", + "patterns": [ + { + "name": "keyword.subcall.gcode", + "match": "CALL O([A-Z0-9]{1,4}).*" + }, + { + "name": "keyword.sub.gcode", + "match": "^O([A-Z0-9]{1,4})(?=\\s|$|\\()" + }, + { + "name": "keyword.subend.gcode", + "match": "^RTS$" + } + ] + }, + "variables": { + "comment": "Local, common, and system variables", + "patterns": [ + { + "name": "var.local.okuma.gcode", + "match": "([ABCDEFGHIJKLMPQRSTUWXYZ][A-Z][A-Z0-9]{0,2})" + }, + { + "name": "var.common.okuma.gcode", + "match": "VC(\\d{1,4}|\\[(\\d{1,4}|VC\\d{1,4}|[A-Z]{2}[A-Z0-9]{0,2})\\])" + }, + { + "name": "var.system.okuma.gcode", + "match": "V[A-Z][A-Z0-9]{1,4}(\\[.*\\])?" + }, + { + "name": "var.local.fanuc.gcode", + "match": "\\#([1-9]|[12][0-9]|3[0-3])(?!\\d)" + }, + { + "name": "var.common.fanuc.gcode", + "match": "\\#([1-9][0-9]{2}})" + }, + { + "name": "var.system.fanuc.gcode", + "match": "\\#([1-9][0-9]{3})(?!\\d)" + } + ] + }, + "address-alphanumeric": { + "comment": "A single letter followed by one or more alphanumeric characters", + "patterns": [ + { + "name": "word.d.gcode", + "match": "D([ABC]|\\d+)" + }, + { + "name": "word.h.gcode", + "match": "H([ABC]|\\d+)" + }, + { + "name": "word.n.gcode", + "match": "^(N)(\\d{1,5}|[A-Z][A-Z0-9]{0,4})(?=\\s|$|\\()", + "captures": { + "0": { + "name": "replace.n" } } - ] - }, - "address-integer": { - "comment": "A single letter followed by an unsigned integer or an expression", - "patterns": [ - { - "name": "word.g.gcode", - "match": "G(\\d{1,3}|(?=\\=))" - }, - { - "name": "word.m.gcode", - "match": "M(\\d{1,3}|(?=\\=))", - "captures": { - "0": { - "name": "replace.m" - } + } + ] + }, + "address-integer": { + "comment": "A single letter followed by an unsigned integer or an expression", + "patterns": [ + { + "name": "word.g.gcode", + "match": "G(\\d{1,3}|(?=\\=))" + }, + { + "name": "word.m.gcode", + "match": "M(\\d{1,3}|(?=\\=))", + "captures": { + "0": { + "name": "replace.m" } - }, - { - "name": "word.t.gcode", - "match": "T(\\d+|(?=\\=))", - "captures": { - "0": { - "name": "replace.t" - } + } + }, + { + "name": "word.t.gcode", + "match": "T(\\d+|(?=\\=))", + "captures": { + "0": { + "name": "replace.t" } } - ] - }, - "address-decimal": { - "comment": "A single letter followed by a signed number, integer or decimal", - "patterns": [ - { - "match": "([ABCEFIJKLPQRSUVWXYZ])([\\-\\+]?\\d{0,6}\\.?\\d*|\\.\\d+|(?=\\=))", - "captures": { - "0": { - "patterns": [ - { - "name": "word.a.gcode", - "match": "A.*" - }, - { - "name": "word.b.gcode", - "match": "B.*" - }, - { - "name": "word.c.gcode", - "match": "C.*" - }, - { - "name": "word.e.gcode", - "match": "E.*" - }, - { - "name": "word.f.gcode", - "match": "F.*", - "captures": { - "0": { - "name": "replace.f" - } + } + ] + }, + "address-decimal": { + "comment": "A single letter followed by a signed number, integer or decimal", + "patterns": [ + { + "match": "([ABCEFIJKLPQRSUVWXYZ])([\\-\\+]?\\d{0,6}\\.?\\d*|\\.\\d+|(?=\\=))", + "captures": { + "0": { + "patterns": [ + { + "name": "word.a.gcode", + "match": "A.*" + }, + { + "name": "word.b.gcode", + "match": "B.*" + }, + { + "name": "word.c.gcode", + "match": "C.*" + }, + { + "name": "word.e.gcode", + "match": "E.*" + }, + { + "name": "word.f.gcode", + "match": "F.*", + "captures": { + "0": { + "name": "replace.f" } - }, - { - "name": "word.i.gcode", - "match": "I.*" - }, - { - "name": "word.j.gcode", - "match": "J.*" - }, - { - "name": "word.k.gcode", - "match": "K.*" - }, - { - "name": "word.l.gcode", - "match": "L.*" - }, - { - "name": "word.p.gcode", - "match": "P.*" - }, - { - "name": "word.q.gcode", - "match": "Q.*" - }, - { - "name": "word.r.gcode", - "match": "R.*" - }, - { - "name": "word.s.gcode", - "match": "S.*", - "captures": { - "0":{ - "name": "replace.s" - } + } + }, + { + "name": "word.i.gcode", + "match": "I.*" + }, + { + "name": "word.j.gcode", + "match": "J.*" + }, + { + "name": "word.k.gcode", + "match": "K.*" + }, + { + "name": "word.l.gcode", + "match": "L.*" + }, + { + "name": "word.p.gcode", + "match": "P.*" + }, + { + "name": "word.q.gcode", + "match": "Q.*" + }, + { + "name": "word.r.gcode", + "match": "R.*" + }, + { + "name": "word.s.gcode", + "match": "S.*", + "captures": { + "0": { + "name": "replace.s" } - }, - { - "name": "word.u.gcode", - "match": "U.*" - }, - { - "name": "word.v.gcode", - "match": "V.*" - }, - { - "name": "word.w.gcode", - "match": "W.*" - }, - { - "name": "word.x.gcode", - "match": "X.*", - "captures": { - "0": { - "name": "replace.x" - } + } + }, + { + "name": "word.u.gcode", + "match": "U.*" + }, + { + "name": "word.v.gcode", + "match": "V.*" + }, + { + "name": "word.w.gcode", + "match": "W.*" + }, + { + "name": "word.x.gcode", + "match": "X.*", + "captures": { + "0": { + "name": "replace.x" } - }, - { - "name": "word.y.gcode", - "match": "Y.*", - "captures": { - "0": { - "name": "replace.y" - } + } + }, + { + "name": "word.y.gcode", + "match": "Y.*", + "captures": { + "0": { + "name": "replace.y" } - }, - { - "name": "word.z.gcode", - "match": "Z.*", - "captures": { - "0": { - "name": "replace.z" - } + } + }, + { + "name": "word.z.gcode", + "match": "Z.*", + "captures": { + "0": { + "name": "replace.z" } } - ] - } + } + ] } } - ] - }, - "comments": { - "patterns": [ - { - "name": "comment.parens.gcode", - "begin": "\\(", - "end": "\\)", - "contentName": "replace.comment" - }, - { - "name": "comment.semi-colon.gcode", - "begin": "\\;", - "end": "$", - "contentName": "replace.comment" - } - ] - } + } + ] + }, + "comments": { + "patterns": [ + { + "name": "comment.parens.gcode", + "begin": "\\(", + "end": "\\)", + "contentName": "replace.comment" + }, + { + "name": "comment.semi-colon.gcode", + "begin": "\\;", + "end": "$", + "contentName": "replace.comment" + } + ] } - } \ No newline at end of file + } +} \ No newline at end of file From c43379fee09ebb179adf5a2a7c6c222fe997b35c Mon Sep 17 00:00:00 2001 From: "Scott M. Wyant" <29161635+scottmwyant@users.noreply.github.com> Date: Fri, 5 Feb 2021 20:26:38 -0500 Subject: [PATCH 4/6] fix(gcode.tmLanguage.json): Color ABC, IJK, UVW Apply the same textmate tokens to ABC, IJK, and UVW addresses as XYZ addresses. --- assets/gcode.tmLanguage.json | 63 ++++++++++++++++++++++++++----- src/grammar/gcode.tmLanguage.json | 63 ++++++++++++++++++++++++++----- 2 files changed, 108 insertions(+), 18 deletions(-) diff --git a/assets/gcode.tmLanguage.json b/assets/gcode.tmLanguage.json index 3326b88..3684c29 100644 --- a/assets/gcode.tmLanguage.json +++ b/assets/gcode.tmLanguage.json @@ -170,15 +170,30 @@ "patterns": [ { "name": "word.a.gcode", - "match": "A.*" + "match": "A.*", + "captures": { + "0": { + "name": "string.regexp" + } + } }, { "name": "word.b.gcode", - "match": "B.*" + "match": "B.*", + "captures": { + "0": { + "name": "comment" + } + } }, { "name": "word.c.gcode", - "match": "C.*" + "match": "C.*", + "captures": { + "0": { + "name": "constant.language" + } + } }, { "name": "word.e.gcode", @@ -195,15 +210,30 @@ }, { "name": "word.i.gcode", - "match": "I.*" + "match": "I.*", + "captures": { + "0": { + "name": "string.regexp" + } + } }, { "name": "word.j.gcode", - "match": "J.*" + "match": "J.*", + "captures": { + "0": { + "name": "comment" + } + } }, { "name": "word.k.gcode", - "match": "K.*" + "match": "K.*", + "captures": { + "0": { + "name": "constant.language" + } + } }, { "name": "word.l.gcode", @@ -232,15 +262,30 @@ }, { "name": "word.u.gcode", - "match": "U.*" + "match": "U.*", + "captures": { + "0": { + "name": "string.regexp" + } + } }, { "name": "word.v.gcode", - "match": "V.*" + "match": "V.*", + "captures": { + "0": { + "name": "comment" + } + } }, { "name": "word.w.gcode", - "match": "W.*" + "match": "W.*", + "captures": { + "0": { + "name": "constant.language" + } + } }, { "name": "word.x.gcode", diff --git a/src/grammar/gcode.tmLanguage.json b/src/grammar/gcode.tmLanguage.json index 285c02a..40f835e 100644 --- a/src/grammar/gcode.tmLanguage.json +++ b/src/grammar/gcode.tmLanguage.json @@ -170,15 +170,30 @@ "patterns": [ { "name": "word.a.gcode", - "match": "A.*" + "match": "A.*", + "captures": { + "0": { + "name": "replace.x" + } + } }, { "name": "word.b.gcode", - "match": "B.*" + "match": "B.*", + "captures": { + "0": { + "name": "replace.y" + } + } }, { "name": "word.c.gcode", - "match": "C.*" + "match": "C.*", + "captures": { + "0": { + "name": "replace.z" + } + } }, { "name": "word.e.gcode", @@ -195,15 +210,30 @@ }, { "name": "word.i.gcode", - "match": "I.*" + "match": "I.*", + "captures": { + "0": { + "name": "replace.x" + } + } }, { "name": "word.j.gcode", - "match": "J.*" + "match": "J.*", + "captures": { + "0": { + "name": "replace.y" + } + } }, { "name": "word.k.gcode", - "match": "K.*" + "match": "K.*", + "captures": { + "0": { + "name": "replace.z" + } + } }, { "name": "word.l.gcode", @@ -232,15 +262,30 @@ }, { "name": "word.u.gcode", - "match": "U.*" + "match": "U.*", + "captures": { + "0": { + "name": "replace.x" + } + } }, { "name": "word.v.gcode", - "match": "V.*" + "match": "V.*", + "captures": { + "0": { + "name": "replace.y" + } + } }, { "name": "word.w.gcode", - "match": "W.*" + "match": "W.*", + "captures": { + "0": { + "name": "replace.z" + } + } }, { "name": "word.x.gcode", From 6d58ddb91483330e785defb48116c43e86bfe32f Mon Sep 17 00:00:00 2001 From: "Scott M. Wyant" <29161635+scottmwyant@users.noreply.github.com> Date: Fri, 5 Feb 2021 20:30:08 -0500 Subject: [PATCH 5/6] fix(gcode.tmLanguage.json): Don't use the 'keyword' token The 'keyword' token is one of the popular tokens that themes color. Since we have to use the popular tokens to get the RGB colors in the right places, they cannot be used elsewhere in the grammar. --- assets/gcode.tmLanguage.json | 6 +++--- src/grammar/gcode.tmLanguage.json | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/gcode.tmLanguage.json b/assets/gcode.tmLanguage.json index 3684c29..a39e29f 100644 --- a/assets/gcode.tmLanguage.json +++ b/assets/gcode.tmLanguage.json @@ -69,15 +69,15 @@ "comment": "Keywords related to sub programs", "patterns": [ { - "name": "keyword.subcall.gcode", + "name": "sub.call.gcode", "match": "CALL O([A-Z0-9]{1,4}).*" }, { - "name": "keyword.sub.gcode", + "name": "sub.name.gcode", "match": "^O([A-Z0-9]{1,4})(?=\\s|$|\\()" }, { - "name": "keyword.subend.gcode", + "name": "sub.end.gcode", "match": "^RTS$" } ] diff --git a/src/grammar/gcode.tmLanguage.json b/src/grammar/gcode.tmLanguage.json index 40f835e..23a032b 100644 --- a/src/grammar/gcode.tmLanguage.json +++ b/src/grammar/gcode.tmLanguage.json @@ -69,15 +69,15 @@ "comment": "Keywords related to sub programs", "patterns": [ { - "name": "keyword.subcall.gcode", + "name": "sub.call.gcode", "match": "CALL O([A-Z0-9]{1,4}).*" }, { - "name": "keyword.sub.gcode", + "name": "sub.name.gcode", "match": "^O([A-Z0-9]{1,4})(?=\\s|$|\\()" }, { - "name": "keyword.subend.gcode", + "name": "sub.end.gcode", "match": "^RTS$" } ] @@ -337,4 +337,4 @@ ] } } -} \ No newline at end of file +} From 7811dd8d163de82e85cb070548591a3822105d48 Mon Sep 17 00:00:00 2001 From: "Scott M. Wyant" <29161635+scottmwyant@users.noreply.github.com> Date: Sat, 6 Feb 2021 14:40:05 -0500 Subject: [PATCH 6/6] feat(dictionary.ts): Update inline definitions on save --- README.md | 2 +- src/hoverProvider/dictionary.ts | 29 ++++++++++------------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b05fc80..9d9ba03 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ You need to add a `gcode.definitions` key to your settings.json file (user setti An inline definition is a comment in your code that matches the following format. An inline definition has a `code` and a `meaning` seperated by `:` or `=`. There may be whitespace on either side of the seperator. The text on the right side of the seperator will show up as hover text in that file. See some examples of inline definitions below. -Note that after you add inline definitions to a file, they won't show up in a hover until you activate the file agian. Either close that file and re-open it, or activate another file then switch back. This prevents the extension from needing to continuously scan your file for definitions. +Note that after you add inline definitions to a file, they won't show up in a hover until the file is saved. This prevents the extension from needing to continuously scan your file for definitions. Examples of inline definitions: diff --git a/src/hoverProvider/dictionary.ts b/src/hoverProvider/dictionary.ts index a260593..151d7cf 100644 --- a/src/hoverProvider/dictionary.ts +++ b/src/hoverProvider/dictionary.ts @@ -13,8 +13,8 @@ export class Dictionary { constructor(fileText?: string) { // Initialize definitions - this.definitionsFromComments = (fileText == undefined) ? {} : this._refreshDefinitionsFromComments(fileText); - this.definitionsFromSettings = this._refreshDefinitionsFromSettings(); + this.definitionsFromComments = (fileText == undefined) ? {} : this.refreshDefinitionsFromComments(fileText); + this.definitionsFromSettings = this.refreshDefinitionsFromSettings(); this.definitions = this.mergeDefinitions(); } @@ -23,9 +23,10 @@ export class Dictionary { // Register a function to parse comments when the active editor changes context.subscriptions.push( - window.onDidChangeActiveTextEditor(event => { - if (event != undefined && event.document.languageId != 'gcode') { - this.refreshDefinitionsFromComments(event.document.getText()); + workspace.onWillSaveTextDocument(event => { + if (event.document.languageId == 'gcode') { + this.definitionsFromComments = this.refreshDefinitionsFromComments(event.document.getText()); + this.definitions = this.mergeDefinitions(); } }) ); @@ -34,7 +35,8 @@ export class Dictionary { context.subscriptions.push( workspace.onDidChangeConfiguration(event => { if (event.affectsConfiguration('gcode.definitions')) { - this.refreshDefinitionsFromSettings(); + this.definitionsFromSettings = this.refreshDefinitionsFromSettings(); + this.definitions = this.mergeDefinitions(); } }) ); @@ -45,21 +47,11 @@ export class Dictionary { return this.definitions[removeLeadingZeros(code)]; } - private refreshDefinitionsFromComments(fileText: string) { - this.definitionsFromComments = this._refreshDefinitionsFromComments(fileText); - this.definitions = this.mergeDefinitions(); - } - - private refreshDefinitionsFromSettings() { - this.definitionsFromSettings = this._refreshDefinitionsFromSettings(); - this.definitions = this.mergeDefinitions(); - } - private mergeDefinitions() { return Object.assign({}, this.definitionsFromSettings, this.definitionsFromComments) } - private _refreshDefinitionsFromComments(fileText: string) { + private refreshDefinitionsFromComments(fileText: string) { function parse(comments: string[]): Definitions { // Change first and last characters from parens to double-quotes @@ -77,10 +69,9 @@ export class Dictionary { const obj = (matches == null) ? {} : parse(matches); return this.removeLeadingZerosFromKeys(obj); - } - private _refreshDefinitionsFromSettings() { + private refreshDefinitionsFromSettings() { let obj = JSON.parse(JSON.stringify(workspace.getConfiguration('gcode.definitions'))); return this.removeLeadingZerosFromKeys(obj); }