Skip to content

Commit

Permalink
Improve VR syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
smikitky committed Jul 7, 2018
1 parent 0c66d08 commit 09e69e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ export default class DicomHoverProvider implements vscode.HoverProvider {
// Since we cannot directly get the scope from here,
// we need to reanalyze the line.
const line = document.lineAt(position.line).text;
const match = line.match(/\s*(\([0-9A-F]{4}\,[0-9A-F]{4}\)) ([A-Z]{2})/);
const match = line.match(
/\s*(\([0-9A-F]{4}\,[0-9A-F]{4}\)) ([A-Z]{2}(\|[A-Z])*)/
);
if (!match) return;
const vrPos = match[0].length - 2;
const vr = match[2];
const vrPos = match[0].length - match[2].length;

// Make sure the cursor is hovering on the VR part
if (position.character < vrPos || vrPos + 1 < position.character) {
if (
position.character < vrPos ||
vrPos + match[2].length < position.character
) {
return null;
}

const vr = document.getText(document.getWordRangeAtPosition(position));
const hover = vrDict[vr] || 'Unknown VR';
return new vscode.Hover(hover);
}
Expand Down
6 changes: 3 additions & 3 deletions syntaxes/dicom-dump.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"patterns": [
{
"match":
"^\\s*(\\([0-9A-F]{4}\\,[0-9A-F]{4}\\)) (..) (\\w+|\\?) ?= ?(.*)",
"^\\s*(\\([0-9A-F]{4}\\,[0-9A-F]{4}\\)) (..(\\|..)*) (\\w+|\\?) ?= ?(.*)",
"captures": {
"1": { "patterns": [{ "include": "#tag" }] },
"2": { "patterns": [{ "include": "#vr" }] },
"3": { "patterns": [{ "include": "#name" }] },
"4": { "patterns": [{ "include": "#val" }] }
"4": { "patterns": [{ "include": "#name" }] },
"5": { "patterns": [{ "include": "#val" }] }
}
}
]
Expand Down

0 comments on commit 09e69e2

Please sign in to comment.