1- using OmniSharp . Extensions . LanguageServer . Protocol ;
21using System . Text . RegularExpressions ;
32using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
4- using OmniSharp . Extensions . LanguageServer . Protocol . Window ;
53using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
6- using System . Collections . Generic ;
74using System . Text ;
5+ using RASharp . Models ;
6+ using OmniSharp . Extensions . LanguageServer . Protocol . Window ;
87
98namespace RAScriptLanguageServer
109{
1110 public class Parser
1211 {
13- private readonly ILanguageServerFacade _router ;
12+ public readonly ILanguageServerFacade _router ;
1413 private readonly string text ;
1514 private readonly TextPositions textPositions ;
1615 private readonly Dictionary < string , Position > functionLocations ;
1716 private readonly Dictionary < string , string [ ] > comments ;
1817 private readonly Dictionary < string , CompletionItemKind > keywordKinds ;
1918 private readonly List < string > keywords ;
2019 private readonly FunctionDefinition [ ] functionDefinitions ;
20+ private int gameID ;
21+ private GetCodeNotes ? codeNotes ;
2122
2223 public Parser ( ILanguageServerFacade router , FunctionDefinitions functionDefinitions , string text )
2324 {
@@ -29,6 +30,7 @@ public Parser(ILanguageServerFacade router, FunctionDefinitions functionDefiniti
2930 this . keywordKinds = new Dictionary < string , CompletionItemKind > ( ) ;
3031 this . keywords = new List < string > ( ) ;
3132 this . functionDefinitions = functionDefinitions . functionDefinitions ;
33+ this . gameID = 0 ; // game id's start at 1 on RA
3234 this . Load ( ) ;
3335 Dictionary < string , CompletionItemKind > . KeyCollection keyColl = this . keywordKinds . Keys ;
3436 foreach ( string k in keyColl )
@@ -37,6 +39,29 @@ public Parser(ILanguageServerFacade router, FunctionDefinitions functionDefiniti
3739 }
3840 }
3941
42+ public void loadCodeNotes ( GetCodeNotes ? codeNotes )
43+ {
44+ this . codeNotes = codeNotes ;
45+ if ( this . codeNotes != null && this . codeNotes . Success )
46+ {
47+ foreach ( var note in this . codeNotes . CodeNotes )
48+ {
49+ this . comments [ note . Address ] = [
50+ $ "`{ note . Address } `",
51+ "---" ,
52+ $ "```txt\n { note . Note } \n ```",
53+ "---" ,
54+ $ "Author: [{ note . User } ](https://retroachievements.org/user/{ note . User } )",
55+ ] ;
56+ }
57+ }
58+ }
59+
60+ public GetCodeNotes ? GetCodeNotes ( )
61+ {
62+ return this . codeNotes ;
63+ }
64+
4065 private void Load ( )
4166 {
4267 for ( int i = 0 ; i < this . functionDefinitions . Length ; i ++ )
@@ -48,6 +73,22 @@ private void Load()
4873 }
4974 if ( text != null && text != "" )
5075 {
76+ foreach ( Match ItemMatch in Regex . Matches ( text , @"\/\/\s*#ID\s*=\s*(\d+)" ) )
77+ {
78+ string gameIDStr = ItemMatch . Groups . Values . ElementAt ( 1 ) . ToString ( ) ;
79+ try
80+ {
81+ int gameID = int . Parse ( gameIDStr ) ;
82+ if ( gameID > 0 )
83+ {
84+ this . gameID = gameID ;
85+ }
86+ }
87+ catch ( FormatException )
88+ {
89+ this . gameID = 0 ; // reset the game id
90+ }
91+ }
5192 foreach ( Match ItemMatch in Regex . Matches ( text , @"(\w+)\s*=" ) )
5293 {
5394 string varName = ItemMatch . Groups . Values . ElementAt ( 1 ) . ToString ( ) ;
@@ -316,7 +357,7 @@ public string[] GetKeywords()
316357 {
317358 return this . keywords . ToArray ( ) ;
318359 }
319-
360+
320361 public CompletionItemKind ? GetKeywordCompletionItemKind ( string keyword )
321362 {
322363 if ( this . keywordKinds . ContainsKey ( keyword ) )
@@ -325,5 +366,10 @@ public string[] GetKeywords()
325366 }
326367 return null ;
327368 }
369+
370+ public int GetGameID ( )
371+ {
372+ return this . gameID ;
373+ }
328374 }
329375}
0 commit comments