Skip to content

Commit a765222

Browse files
committed
Go to property in Index
1 parent 12330b2 commit a765222

File tree

2 files changed

+123
-10
lines changed

2 files changed

+123
-10
lines changed

src/providers/ObjectScriptDefinitionProvider.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,37 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
6969
pos += part.length;
7070
}
7171

72+
const onProperty = /(\b(?:On)\b %?\b[a-zA-Z][a-zA-Z0-9]+\b)/i;
73+
parts = lineText.split(onProperty);
74+
pos = 0;
75+
for (const part of parts) {
76+
if (part.match(onProperty)) {
77+
const [keyword, name] = part.split(" ");
78+
const start = pos + keyword.length + 1;
79+
if (this.isValid(position, start, name.length)) {
80+
return [this.makePropertyDefinition(document, name)];
81+
}
82+
}
83+
pos += part.length;
84+
}
85+
const onPropertyList = /(\b(?:On)\b \([^)]+\))/i;
86+
parts = lineText.split(onPropertyList);
87+
pos = 0;
88+
for (const part of parts) {
89+
if (part.match(onPropertyList)) {
90+
const listProperties = /\(([^)]+)\)/.exec(part)[1].split(/\s*,\s*/);
91+
return listProperties
92+
.map(name => {
93+
name = name.trim();
94+
const start = pos + part.indexOf(name);
95+
if (this.isValid(position, start, name.length)) {
96+
return this.makePropertyDefinition(document, name);
97+
}
98+
})
99+
.filter(el => el != null);
100+
}
101+
pos += part.length;
102+
}
72103
const asClassList = /(\b(?:Extends)\b \([^)]+\))/i;
73104
parts = lineText.split(asClassList);
74105
pos = 0;
@@ -227,6 +258,37 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
227258
};
228259
}
229260

261+
public makePropertyDefinition(document: vscode.TextDocument, name: string): vscode.DefinitionLink {
262+
const property = new RegExp(`(?<=^Property\\s)\\b${name}\\b`, "i");
263+
let descrLine = -1;
264+
for (let i = 0; i < document.lineCount; i++) {
265+
const line = document.lineAt(i).text;
266+
if (descrLine < 0 && line.match(/^\/\/\//)) {
267+
descrLine = i;
268+
}
269+
if (descrLine >= 0 && !line.trim().length) {
270+
descrLine = -1;
271+
}
272+
const propertyMatch = line.match(property);
273+
if (propertyMatch) {
274+
const targetSelectionRange = new vscode.Range(
275+
new vscode.Position(i, propertyMatch.index),
276+
new vscode.Position(i, propertyMatch.index + name.length)
277+
);
278+
const targetRange = new vscode.Range(
279+
new vscode.Position(descrLine >= 0 ? descrLine : i, 0),
280+
new vscode.Position(i, propertyMatch.index + line.length)
281+
);
282+
return {
283+
targetUri: document.uri,
284+
targetRange,
285+
targetSelectionRange,
286+
};
287+
}
288+
}
289+
return null;
290+
}
291+
230292
public makeRoutineDefinition(
231293
workspaceFolder: string,
232294
position: vscode.Position,

syntaxes/objectscript-class.tmLanguage.json

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,29 @@
258258
}
259259
},
260260
{
261-
"match": "(?i)^(\\bRelationship\\b)(\\s+)((?:%?[a-zA-Z][0-9a-zA-Z]*(?:_[0-9a-zA-Z]+)*)|(?:\"[^\".]+\"))",
262-
"captures": {
263-
"1": {
264-
"name": "keyword.objectscript_class"
265-
},
266-
"2": {
267-
"name": "whitespace.objectscript_class"
261+
"begin": "(?i)^(\\bRelationship\\b)(\\s+)((?:%?[a-zA-Z][0-9a-zA-Z]*(?:_[0-9a-zA-Z]+)*)|(?:\"[^\".]+\"))",
262+
"beginCaptures": {
263+
"1": {
264+
"name": "keyword.objectscript_class"
265+
},
266+
"2": {
267+
"name": "whitespace.objectscript_class"
268+
},
269+
"3": {
270+
"name": "entity.other.attribute-name.objectscript_class"
271+
}
268272
},
269-
"3": {
270-
"name": "entity.other.attribute-name.objectscript_class"
273+
"patterns": [
274+
{
275+
"include": "#relationship"
276+
}
277+
],
278+
"end": "(;)",
279+
"endCaptures": {
280+
"1": {
281+
"name": "punctuation.objectscript_class"
282+
}
271283
}
272-
}
273284
},
274285
{
275286
"begin": "(?i)^(\\b(?:Class|Client)?Method\\b)(\\s+)((?:%?[a-zA-Z][0-9a-zA-Z]*(?:_[0-9a-zA-Z]+)*)|(?:\"[^\".]+\"))",
@@ -541,6 +552,36 @@
541552
"name": "entity.other.attribute-name.objectscript_class"
542553
}
543554
}
555+
},
556+
{
557+
"begin": "(?i)(\\bOn\\b)(\\s+)(\\()",
558+
"beginCaptures": {
559+
"1": {
560+
"name": "keyword.objectscript_class"
561+
},
562+
"2": {
563+
"name": "whitespace.objectscript_class"
564+
},
565+
"3": {
566+
"name": "punctuation.objectscript_class"
567+
}
568+
},
569+
"patterns": [
570+
{
571+
"match": "(%?[a-zA-Z][0-9a-zA-Z]*(?:_[0-9a-zA-Z]+)*(?:\\.[a-zA-Z][0-9a-zA-Z]*(?:_[0-9a-zA-Z]+)*)*)",
572+
"captures": {
573+
"1": {
574+
"name": "entity.other.attribute-name.objectscript_class"
575+
}
576+
}
577+
}
578+
],
579+
"end": "(\\))",
580+
"endCaptures": {
581+
"1": {
582+
"name": "punctuation.objectscript_class"
583+
}
584+
}
544585
}
545586
]
546587
},
@@ -589,6 +630,16 @@
589630
}
590631
]
591632
},
633+
"relationship": {
634+
"patterns": [
635+
{
636+
"include": "#as"
637+
},
638+
{
639+
"include": "#params"
640+
}
641+
]
642+
},
592643
"parameter": {
593644
"patterns": [
594645
{

0 commit comments

Comments
 (0)