Skip to content

Commit

Permalink
[fix] bug fix
Browse files Browse the repository at this point in the history
- hover on string fixed.
- grammars for switch condition fixed.
  • Loading branch information
salbert11 committed Dec 29, 2023
1 parent 3cc2e9e commit b04765c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 47 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "images/pineicon.png",
"publisher": "salbert11",
"license": "MIT",
"version": "3.2.3",
"version": "3.2.4-beta-2",
"engines": {
"vscode": "^1.62.0"
},
Expand Down
50 changes: 32 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ const BUILT_IN_FUNC = hover_func as FuncPopupBlock[];
const BUILT_IN_VAR = hover_var as ConstPopupBlock[];
const BUILT_IN_CONST = hover_const as ConstPopupBlock[];

function testComment(document: vscode.TextDocument, position: vscode.Position, hoverLineText: string){
let testCommentPattern = new RegExp("//.*");
if (testCommentPattern.test(hoverLineText)){
let hoverRange = document.getWordRangeAtPosition(position, testCommentPattern);
if (hoverRange){
return true;
}
else {
return false;
}
}
}

function testString(document: vscode.TextDocument, position: vscode.Position, hoverLineText: string){
let testStringPattern = new RegExp("(?:\".*?\")|(?:\'.*?\')");
if (testStringPattern.test(hoverLineText)){
let hoverRange = document.getWordRangeAtPosition(position, testStringPattern);
if (hoverRange){
return true;
}
else {
return false;
}
}
}

export function activate(context: vscode.ExtensionContext) {

console.log('Pinescript-helper activated');
Expand All @@ -41,12 +67,8 @@ export function activate(context: vscode.ExtensionContext) {
let hoverRange;
const hoverLineText = document.lineAt(position.line).text;

let testCommentPattern = new RegExp("//.*");
if (testCommentPattern.test(hoverLineText)){
hoverRange = document.getWordRangeAtPosition(position, testCommentPattern);
if (hoverRange){
return null;
}
if (testComment(document, position, hoverLineText) || testString(document, position, hoverLineText)){
return null;
}

for (let index = 0; index < BUILT_IN_FUNC.length; index++) {
Expand Down Expand Up @@ -88,12 +110,8 @@ export function activate(context: vscode.ExtensionContext) {
let hoverRange;
const hoverLineText = document.lineAt(position.line).text;

let testCommentPattern = new RegExp("//.*");
if (testCommentPattern.test(hoverLineText)){
hoverRange = document.getWordRangeAtPosition(position, testCommentPattern);
if (hoverRange){
return null;
}
if (testComment(document, position, hoverLineText) || testString(document, position, hoverLineText)){
return null;
}

for (let index = 0; index < BUILT_IN_VAR.length; index++) {
Expand Down Expand Up @@ -130,12 +148,8 @@ export function activate(context: vscode.ExtensionContext) {
let hoverRange;
const hoverLineText = document.lineAt(position.line).text;

let testCommentPattern = new RegExp("//.*");
if (testCommentPattern.test(hoverLineText)){
hoverRange = document.getWordRangeAtPosition(position, testCommentPattern);
if (hoverRange){
return null;
}
if (testComment(document, position, hoverLineText) || testString(document, position, hoverLineText)){
return null;
}

for (let index = 0; index < BUILT_IN_CONST.length; index++) {
Expand Down
45 changes: 19 additions & 26 deletions syntaxes/ps.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -1268,21 +1268,6 @@
{
"match": "\\b([a-zA-Z_]\\w*)\\b(?=\\s*\\()",
"name": "entity.name.function.ps"
},
{
"match": "(\\()\\s*(\\))\\s*(=>)",
"captures": {
"1":{"name":"meta.brace.round.ps"},
"2":{"name":"meta.brace.round.ps"},
"3":{"name":"storage.type.function.arrow.ps"}
}
},
{
"match": "(\\))\\s*(=>)",
"captures": {
"1":{"name":"meta.brace.round.ps"},
"2":{"name":"storage.type.function.arrow.ps"}
}
}
]
},
Expand Down Expand Up @@ -1324,22 +1309,22 @@
"include": "#collection_new"
},
{
"match": "(?<![\\.]\\s*)(?:\\b(export)\\s+)?\\b(type)\\s+([a-zA-Z_]\\w*)\\b(?=\\s*(?:\\s*//.*)?$)",
"match": "^(?:(export)\\s+)?\\b(type)\\s+([a-zA-Z_]\\w*)\\b(?=\\s*(?:\\s*//.*)?$)",
"captures": {
"1": {"name": "keyword.control.export.ps"},
"2": {"name": "storage.type.type.ps"},
"3": {"name": "support.type.primitive.ps"}
}
},
{
"match": "(?<![\\.]\\s*)\\b(export)\\s+(type)\\b",
"match": "^(export)\\s+(type)\\b",
"captures": {
"1": {"name": "keyword.control.export.ps"},
"2": {"name": "storage.type.type.ps"}
}
},
{
"match": "(?<![\\.]\\s*)\\b(export)\\s+(method)\\b",
"match": "^(export)\\s+(method)\\b",
"captures": {
"1": {"name": "keyword.control.export.ps"},
"2": {"name": "storage.type.function.ps"}
Expand Down Expand Up @@ -1486,28 +1471,36 @@
"multiline_functions":{
"patterns": [
{
"match": "(?<=^(?:\\s*export\\s*)?(?:\\s*method\\s*)?\\s*\\b\\w+\\s*\\()([\\s\\S]*)(?=\\)\\s*\\=>)",
"captures": {"1":{"patterns":[{"include": "#functions_parameters_capture"}]}}
"match": "(?<=^(?:export\\s+)?(?:method\\s+)?\\b\\w+\\s*\\()([\\s\\S]*)(\\))\\s*(\\=>)",
"captures": {
"1":{"patterns":[{"include": "#functions_parameters_capture"}]},
"2":{"name":"meta.brace.round.ps"},
"3":{"name":"storage.type.function.arrow.ps"}
}
},
{
"match": "(?<=^\\s*export\\s+(?:method\\s+)?\\b\\w+\\s*\\()\\b([\\w][^\\(\\)]*)(?=\\s*\\,\\s*(?://.*)?$)",
"match": "(?<=^export\\s+(?:method\\s+)?\\b\\w+\\s*\\()\\b([\\w][^\\(\\)]*)(?=\\s*\\,\\s*(?://.*)?$)",
"captures": {"1":{"patterns":[{"include": "#functions_parameters_capture"}]}}
},
{
"match": "(?<=^\\s*(?:export\\s+)?method\\s+\\b\\w+\\s*\\()\\b([\\w][^\\(\\)]*)(?=\\s*\\,\\s*(?://.*)?$)",
"match": "(?<=^(?:export\\s+)?method\\s+\\b\\w+\\s*\\()\\b([\\w][^\\(\\)]*)(?=\\s*\\,\\s*(?://.*)?$)",
"captures": {"1":{"patterns":[{"include": "#functions_parameters_capture"}]}}
},
{
"match": "(?<=^\\s*(?:export\\s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\\]))?\\s+)?\\b\\w+\\s*(?:\\=\\s*[\\w\\.\\#]+)?\\s*)*)(?=\\s*\\,\\s*(?://.*)?$)",
"captures": {"1":{"patterns":[{"include": "#functions_parameters_capture"}]}}
},
{
"match": "(?<=^\\s*)\\b([\\w][^\\(\\)]*)(?=\\)\\s*\\=>)",
"captures": {"1":{"patterns":[{"include": "#functions_parameters_capture"}]}}
"match": "(?<=^\\s+)\\b([\\w][^\\(\\)]*)(\\))\\s*(\\=>)",
"captures": {
"1":{"patterns":[{"include": "#functions_parameters_capture"}]},
"2":{"name":"meta.brace.round.ps"},
"3":{"name":"storage.type.function.arrow.ps"}
}
}
]
},
Expand Down

0 comments on commit b04765c

Please sign in to comment.