@@ -13,10 +13,74 @@ export class ObjectScriptDiagnosticProvider {
13
13
14
14
public updateDiagnostics ( document : vscode . TextDocument ) {
15
15
if ( document . languageId . startsWith ( "objectscript" ) ) {
16
- this . _collection . set ( document . uri , [ ...this . commands ( document ) , ...this . functions ( document ) ] ) ;
16
+ this . _collection . set ( document . uri , [
17
+ ...this . classMembers ( document ) ,
18
+ ...this . commands ( document ) ,
19
+ ...this . functions ( document ) ,
20
+ ] ) ;
17
21
}
18
22
}
19
23
24
+ private classMembers ( document : vscode . TextDocument ) : vscode . Diagnostic [ ] {
25
+ const result = new Array < vscode . Diagnostic > ( ) ;
26
+ const isClass = document . fileName . toLowerCase ( ) . endsWith ( ".cls" ) ;
27
+ if ( ! isClass ) {
28
+ return [ ] ;
29
+ }
30
+
31
+ const map = new Map < string , string > ( ) ;
32
+ let inComment = false ;
33
+
34
+ for ( let i = 0 ; i < document . lineCount ; i ++ ) {
35
+ const line = document . lineAt ( i ) ;
36
+ const text = this . stripLineComments ( line . text ) ;
37
+
38
+ if ( text . match ( / \/ \* / ) ) {
39
+ inComment = true ;
40
+ }
41
+
42
+ if ( inComment ) {
43
+ if ( text . match ( / \* \/ / ) ) {
44
+ inComment = false ;
45
+ }
46
+ continue ;
47
+ }
48
+
49
+ const memberMatch = text . match (
50
+ / ^ ( C l a s s | P r o p e r t y | R e l a t i o n s h i p | I n d e x | C l a s s M e t h o d | M e t h o d | X D a t a | Q u e r y | T r i g g e r | F o r e i g n K e y | P r o j e c t i o n | P a r a m e t e r ) \s ( \b [ ^ ( ] + \b ) / i
51
+ ) ;
52
+ if ( memberMatch ) {
53
+ const [ fullMatch , type , name ] = memberMatch ;
54
+ const simpleType = type
55
+ . toLowerCase ( )
56
+ . replace ( "classmethod" , "method" )
57
+ . replace ( "relationship" , "property" ) ;
58
+ const key = simpleType === "class" ? simpleType : [ simpleType , name ] . join ( ":" ) ;
59
+ if ( map . has ( key ) ) {
60
+ const original = map . get ( key ) ;
61
+ const pos = line . text . indexOf ( name ) ;
62
+ const range = new vscode . Range ( new vscode . Position ( i , pos ) , new vscode . Position ( i , pos + name . length ) ) ;
63
+ result . push ( {
64
+ code : "" ,
65
+ message : "Element name conflict" ,
66
+ range,
67
+ severity : vscode . DiagnosticSeverity . Error ,
68
+ source : "" ,
69
+ relatedInformation : [
70
+ new vscode . DiagnosticRelatedInformation (
71
+ new vscode . Location ( document . uri , range ) ,
72
+ `'${ original } ' already defined earlier`
73
+ ) ,
74
+ ] ,
75
+ } ) ;
76
+ }
77
+ map . set ( key , fullMatch ) ;
78
+ }
79
+ }
80
+
81
+ return result ;
82
+ }
83
+
20
84
private stripLineComments ( text : string ) {
21
85
text = text . replace ( / \/ \/ .* $ / , "" ) ;
22
86
text = text . replace ( / # + ; .* $ / , "" ) ;
0 commit comments