@@ -65,9 +65,47 @@ protected override void AppendFormat (string content, StringBuilder sb, FormatFl
6565 sb . Append ( content ) ;
6666 //base.AppendFormat (content, sb, flags, r, g, b);
6767 }
68- }
68+ }
69+
70+ public class VDserverParseCacheView : ParseCacheView
71+ {
72+ #region Properties
73+ readonly List < RootPackage > packs ;
74+ #endregion
75+
76+ #region Constructors
77+ public VDserverParseCacheView ( IEnumerable < string > packageRoots )
78+ {
79+ this . packs = new List < RootPackage > ( ) ;
80+ Add ( packageRoots ) ;
81+ }
82+
83+ public VDserverParseCacheView ( IEnumerable < RootPackage > packages )
84+ {
85+ this . packs = new List < RootPackage > ( packages ) ;
86+ }
87+ #endregion
88+
89+ public override IEnumerable < RootPackage > EnumRootPackagesSurroundingModule ( DModule module )
90+ {
91+ return packs ;
92+ }
93+
94+ public void Add ( RootPackage pack )
95+ {
96+ if ( pack != null && ! packs . Contains ( pack ) )
97+ packs . Add ( pack ) ;
98+ }
99+
100+ public void Add ( IEnumerable < string > roots )
101+ {
102+ RootPackage rp ;
103+ foreach ( var r in roots )
104+ if ( ( rp = GlobalParseCache . GetRootPackage ( r ) ) != null && ! packs . Contains ( rp ) )
105+ packs . Add ( rp ) ;
106+ }
107+ }
69108
70-
71109
72110 [ ComVisible ( true ) , Guid ( IID . VDServer ) ]
73111 [ ClassInterface ( ClassInterfaceType . None ) ]
@@ -100,14 +138,52 @@ public DModule GetModule(string fileName)
100138 public VDServer ( )
101139 {
102140 // MessageBox.Show("VDServer()");
103- }
104-
105- public void ConfigureSemanticProject ( string filename , string imp , string stringImp , string versionids , string debugids , uint flags )
141+ }
142+
143+ private static string normalizePath ( string path )
144+ {
145+ path = Path . GetFullPath ( path ) ;
146+ return path . ToLower ( ) ;
147+ }
148+
149+ private static string normalizeDir ( string dir )
150+ {
151+ dir = normalizePath ( dir ) ;
152+ if ( ! dir . EndsWith ( "\\ " ) )
153+ dir += '\\ ' ;
154+ return dir ;
155+ }
156+
157+ private string [ ] uniqueDirectories ( string imp )
158+ {
159+ var impDirs = imp . Split ( '\n ' ) ;
160+ string [ ] normDirs = new string [ impDirs . Length ] ;
161+ for ( int i = 0 ; i < impDirs . Length ; i ++ )
162+ normDirs [ i ] = normalizeDir ( impDirs [ i ] ) ;
163+
164+ string [ ] uniqueDirs = new string [ impDirs . Length ] ;
165+ int unique = 0 ;
166+ for ( int i = 0 ; i < normDirs . Length ; i ++ )
167+ {
168+ int j ;
169+ for ( j = 0 ; j < normDirs . Length ; j ++ )
170+ if ( i != j && normDirs [ i ] . StartsWith ( normDirs [ j ] ) )
171+ if ( normDirs [ i ] != normDirs [ j ] || j < i )
172+ break ;
173+ if ( j >= normDirs . Length )
174+ uniqueDirs [ unique ++ ] = normDirs [ i ] ;
175+ }
176+
177+ Array . Resize ( ref uniqueDirs , unique ) ;
178+ return uniqueDirs ;
179+ }
180+
181+ public void ConfigureSemanticProject ( string filename , string imp , string stringImp , string versionids , string debugids , uint flags )
106182 {
107183 if ( _imports != imp )
108- {
109- var impDirs = imp . Split ( ' \n ' ) ;
110- GlobalParseCache . BeginAddOrUpdatePaths ( impDirs ) ;
184+ {
185+ string [ ] uniqueDirs = uniqueDirectories ( imp ) ;
186+ GlobalParseCache . BeginAddOrUpdatePaths ( uniqueDirs ) ;
111187 }
112188 _imports = imp ;
113189 _stringImports = stringImp ;
@@ -124,7 +200,8 @@ public void ClearSemanticProject()
124200 //throw new NotImplementedException();
125201 }
126202 public void UpdateModule ( string filename , string srcText , bool verbose )
127- {
203+ {
204+ filename = normalizePath ( filename ) ;
128205 DModule ast ;
129206 try
130207 {
@@ -159,8 +236,9 @@ static int getCodeOffset(string s, CodeLocation loc)
159236 }
160237
161238 public void GetTip ( string filename , int startLine , int startIndex , int endLine , int endIndex )
162- {
163- var ast = GetModule ( filename ) ;
239+ {
240+ filename = normalizePath ( filename ) ;
241+ var ast = GetModule ( filename ) ;
164242
165243 if ( ast == null )
166244 throw new COMException ( "module not found" , 1 ) ;
@@ -176,14 +254,14 @@ public void GetTip(string filename, int startLine, int startIndex, int endLine,
176254 // codeOffset+1 because otherwise it does not work on the first character
177255 _editorData . CaretOffset = getCodeOffset ( _editorData . ModuleCode , _tipStart ) + 1 ;
178256
179- ISyntaxRegion sr ;
180- DResolver . NodeResolutionAttempt attempt ;
181- var types = DResolver . ResolveTypeLoosely ( _editorData , out attempt , out sr ) ;
257+ ISyntaxRegion sr = DResolver . GetScopedCodeObject ( _editorData ) ;
258+ LooseResolution . NodeResolutionAttempt attempt ;
259+ var types = sr != null ? LooseResolution . ResolveTypeLoosely ( _editorData , sr , out attempt ) : null ;
182260
183261 _tipText . Clear ( ) ;
184262
185263 if ( types != null )
186- {
264+ {
187265 if ( sr != null )
188266 {
189267 _tipStart = sr . Location ;
@@ -220,8 +298,9 @@ public void GetTipResult(out int startLine, out int startIndex, out int endLine,
220298 }
221299
222300 public void GetSemanticExpansions ( string filename , string tok , uint line , uint idx , string expr )
223- {
224- var ast = GetModule ( filename ) ;
301+ {
302+ filename = normalizePath ( filename ) ;
303+ var ast = GetModule ( filename ) ;
225304
226305 if ( ast == null )
227306 throw new COMException ( "module not found" , 1 ) ;
@@ -254,8 +333,9 @@ public void GetSemanticExpansionsResult(out string stringList)
254333 }
255334
256335 public void GetParseErrors ( string filename , out string errors )
257- {
258- var ast = GetModule ( filename ) ;
336+ {
337+ filename = normalizePath ( filename ) ;
338+ var ast = GetModule ( filename ) ;
259339
260340 if ( ast == null )
261341 throw new COMException ( "module not found" , 1 ) ;
@@ -276,6 +356,7 @@ public void GetParseErrors(string filename, out string errors)
276356
277357 public void IsBinaryOperator ( string filename , uint startLine , uint startIndex , uint endLine , uint endIndex , out bool pIsOp )
278358 {
359+ filename = normalizePath ( filename ) ;
279360 var ast = GetModule ( filename ) ;
280361
281362 if ( ast == null )
@@ -299,8 +380,9 @@ public void GetLastMessage(out string message)
299380 }
300381
301382 public void GetDefinition ( string filename , int startLine , int startIndex , int endLine , int endIndex )
302- {
303- var ast = GetModule ( filename ) ;
383+ {
384+ filename = normalizePath ( filename ) ;
385+ var ast = GetModule ( filename ) ;
304386
305387 if ( ast == null )
306388 throw new COMException ( "module not found" , 1 ) ;
@@ -314,11 +396,11 @@ public void GetDefinition(string filename, int startLine, int startIndex, int en
314396 _editorData . SyntaxTree = ast as DModule ;
315397 _editorData . ModuleCode = _sources [ filename ] ;
316398 // codeOffset+1 because otherwise it does not work on the first character
317- _editorData . CaretOffset = getCodeOffset ( _editorData . ModuleCode , _tipStart ) + 2 ;
318-
319- ISyntaxRegion sr ;
320- DResolver . NodeResolutionAttempt attempt ;
321- var rr = DResolver . ResolveTypeLoosely ( _editorData , out attempt , out sr ) ;
399+ _editorData . CaretOffset = getCodeOffset ( _editorData . ModuleCode , _tipStart ) + 2 ;
400+
401+ ISyntaxRegion sr = DResolver . GetScopedCodeObject ( _editorData ) ;
402+ LooseResolution . NodeResolutionAttempt attempt ;
403+ var rr = sr != null ? LooseResolution . ResolveTypeLoosely ( _editorData , sr , out attempt ) : null ;
322404
323405 _tipText . Clear ( ) ;
324406 if ( rr != null )
@@ -355,6 +437,7 @@ public void GetDefinitionResult(out int startLine, out int startIndex, out int e
355437
356438 public void GetReferences ( string filename , string tok , uint line , uint idx , string expr )
357439 {
440+ filename = normalizePath ( filename ) ;
358441 var ast = GetModule ( filename ) ;
359442
360443 if ( ast == null )
@@ -369,9 +452,9 @@ public void GetReferences(string filename, string tok, uint line, uint idx, stri
369452
370453 _references = null ;
371454
372- ISyntaxRegion sr ;
373- DResolver . NodeResolutionAttempt attempt ;
374- var rr = DResolver . ResolveTypeLoosely ( _editorData , out attempt , out sr ) ;
455+ ISyntaxRegion sr = DResolver . GetScopedCodeObject ( _editorData ) ;
456+ LooseResolution . NodeResolutionAttempt attempt ;
457+ var rr = sr != null ? LooseResolution . ResolveTypeLoosely ( _editorData , sr , out attempt ) : null ;
375458
376459 StringBuilder refs = new StringBuilder ( ) ;
377460 if ( rr != null )
@@ -399,7 +482,7 @@ public void GetReferences(string filename, string tok, uint line, uint idx, stri
399482
400483 private static void GetReferencesInModule ( DModule ast , StringBuilder refs , DNode n , ResolutionContext ctxt )
401484 {
402- var res = ReferencesFinder . Scan ( ast , n , ctxt ) ;
485+ var res = ReferencesFinder . SearchModuleForASTNodeReferences ( ast , n , ctxt ) ;
403486
404487 int cnt = res . Count ( ) ;
405488 foreach ( var r in res )
@@ -439,9 +522,10 @@ void _setupEditorData()
439522 if ( ( _flags & 64 ) != 0 )
440523 versions += "GNU\n " ;
441524 else
442- versions += "DigitalMars\n " ;
443-
444- _editorData . ParseCache = new ParseCacheView ( _imports . Split ( '\n ' ) ) ;
525+ versions += "DigitalMars\n " ;
526+
527+ string [ ] uniqueDirs = uniqueDirectories ( _imports ) ;
528+ _editorData . ParseCache = new VDserverParseCacheView ( uniqueDirs ) ;
445529 _editorData . IsDebug = ( _flags & 2 ) != 0 ;
446530 _editorData . DebugLevel = ( _flags >> 16 ) & 0xff ;
447531 _editorData . VersionNumber = ( _flags >> 8 ) & 0xff ;
0 commit comments