[svn] r6900: vs-plugin/trunk:
Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
Nemerle.Compi...
IT
svnadmin at nemerle.org
Wed Nov 15 06:40:49 CET 2006
Log:
Namespace dependent keywords.
Author: IT
Date: Wed Nov 15 06:40:42 2006
New Revision: 6900
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n Wed Nov 15 06:40:42 2006
@@ -105,6 +105,47 @@
find_decl(_compileUnits[fileIndex])
}
+ public GetActiveEnv(fileIndex : int, line : int) : GlobalEnv * int * int
+ {
+ mutable env;
+ mutable start = 0;
+ mutable end = int.MaxValue;
+
+ def loop(decl : Decl)
+ {
+ | Namespace as ns =>
+
+ if (line >= ns.Location.Line)
+ {
+ if (line <= ns.Location.EndLine)
+ {
+ start = ns.Location.Line;
+ end = ns.Location.EndLine;
+ env = ns.InsideEnv;
+
+ foreach (d in ns.Decls)
+ loop(d);
+ }
+ else
+ {
+ start = ns.Location.EndLine + 1;
+ }
+ }
+ else
+ {
+ end = ns.Location.Line - 1;
+ }
+
+ | _ => ()
+ }
+
+ def decl = _compileUnits[fileIndex];
+
+ loop(decl);
+
+ (env, start, end)
+ }
+
/// Finds the innermost top level construction (namespace, class,
/// using, attribute) located at filePath, line, and col.
public GetActiveDecl([NotNull] filePath : string, line : int, col : int) : Decl
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n Wed Nov 15 06:40:42 2006
@@ -19,7 +19,7 @@
Keywords = manager.CoreEnv.Keywords;
}
- public SetLine(line : string, offset : int) : void
+ public SetLine(line : string, offset : int, env : GlobalEnv) : void
{
base.reader = line;
base.pos = offset;
@@ -36,6 +36,8 @@
_quotationCount = -1;
_tokenInfo.IsEndOfLine = eol();
+
+ Keywords = (if (env != null) env else Manager.CoreEnv).Keywords;
}
mutable _last_line : int;
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Properties.n Wed Nov 15 06:40:42 2006
@@ -44,7 +44,7 @@
}
}
- /// Íå èñïîëüçóåéòå ýòîò ñâîéñòâî! Ïîëüçóéòåñü ñâîéñòâîì Project.
+ [Obsolete("Do not use this property. Use the Project property instead.")]
public RawProject : Project
{
get
Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs Wed Nov 15 06:40:42 2006
@@ -147,7 +147,7 @@
public override Source CreateSource(IVsTextLines buffer)
{
- return new NemerleSource(this, buffer, new Colorizer(this, buffer, GetScanner(buffer)));
+ return new NemerleSource(this, buffer, GetColorizer(buffer));
}
public override CodeWindowManager CreateCodeWindowManager(IVsCodeWindow codeWindow, Source source)
@@ -179,11 +179,31 @@
return _preferences;
}
+ #region Colorizer
+
+ Dictionary<IVsTextLines, NemerleColorizer> _colorizers = new Dictionary<IVsTextLines,NemerleColorizer>();
+
+ public override Colorizer GetColorizer(IVsTextLines buffer)
+ {
+ NemerleColorizer colorizer;
+
+ if (!_colorizers.TryGetValue(buffer, out colorizer))
+ {
+ colorizer = new NemerleColorizer(this, buffer, (NemerleScanner)GetScanner(buffer));
+
+ _colorizers.Add(buffer, colorizer);
+ }
+
+ return colorizer;
+ }
+
public override IScanner GetScanner(IVsTextLines buffer)
{
return new NemerleScanner(this, buffer);
}
+ #endregion
+
#region ParseSource
public override AuthoringScope ParseSource(ParseRequest request)
@@ -454,26 +474,6 @@
#endregion
- #region Colorizer
-
- Dictionary<IVsTextLines, NemerleColorizer> _colorizers = new Dictionary<IVsTextLines,NemerleColorizer>();
-
- public override Colorizer GetColorizer(IVsTextLines buffer)
- {
- NemerleColorizer colorizer;
-
- if (!_colorizers.TryGetValue(buffer, out colorizer))
- {
- colorizer = new NemerleColorizer(this, buffer, (NemerleScanner)GetScanner(buffer));
-
- _colorizers.Add(buffer, colorizer);
- }
-
- return colorizer;
- }
-
- #endregion
-
public override ImageList GetImageList()
{
return base.GetImageList();
Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleScanner.cs Wed Nov 15 06:40:42 2006
@@ -3,6 +3,7 @@
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;
+using Nemerle.Builtins;
using Nemerle.Compiler;
using Nemerle.Completion2;
@@ -23,6 +24,7 @@
internal int _currentLine = -1;
internal TokenColor _lastColor;
internal bool _colorizeEnd;
+ internal NemerleSource _source;
private ScanLexer _lexer;
private ScanLexer GetLexer()
@@ -56,8 +58,6 @@
return _lexer;
}
- // Its calling depends on IVsColorizer.GetStateMaintenanceFlag, which defaults to true.
- //
public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
{
if (_lexer == null)
@@ -79,12 +79,49 @@
return !info.IsEndOfLine;
}
+ Nemerle.Completion2.Project _prevProject;
+ GlobalEnv _env;
+ int _envStartLine;
+ int _envEndLine = -1;
+
public void SetSource(string source, int offset)
{
+ //System.Diagnostics.Debug.WriteLine(string.Format("Scan line {0}", _currentLine));
+
ScanLexer lexer = GetLexer();
if (lexer != null)
- lexer.SetLine(source, offset);
+ {
+ if (_currentLine >= 0 && source.Length > 0)
+ {
+ if (_source != null && _source.ProjectInfo != null)
+ {
+#pragma warning disable 618
+ Nemerle.Completion2.Project project = _source.ProjectInfo.Engine.RawProject;
+#pragma warning restore 618
+
+ // Project is set to null after it's recompiled.
+ //
+ if (_prevProject != project)
+ {
+ _prevProject = project;
+ _envEndLine = -1;
+ }
+
+ if (_currentLine < _envStartLine || _currentLine > _envEndLine)
+ {
+ Tuple<GlobalEnv, int, int> ret =
+ project.GetActiveEnv(_source.FileIndex, _currentLine + 1);
+
+ _env = ret.field0;
+ _envStartLine = ret.field1 - 1;
+ _envEndLine = ret.field2 - 1;
+ }
+ }
+ }
+
+ lexer.SetLine(source, offset, _env);
+ }
}
}
}
Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs Wed Nov 15 06:40:42 2006
@@ -20,29 +20,70 @@
public class NemerleSource : Source
{
+ #region Init
+
public NemerleSource(NemerleLanguageService service, IVsTextLines textLines, Colorizer colorizer)
: base(service, textLines, colorizer)
{
string path = GetFilePath();
- ProjectInfo info = ProjectInfo.FindProject(path);
- if (info != null)
- info.AddSource(this);
+ _projectInfo = ProjectInfo.FindProject(path);
+
+ if (_projectInfo != null)
+ {
+ _projectInfo.AddSource(this);
+
+ _fileIndex = _projectInfo.Project.CompileUnits.GetFileIndex(path);
+ }
LastParseTime = 0;
+
+ NemerleScanner scanner = colorizer.Scanner as NemerleScanner;
+
+ if (scanner != null)
+ scanner._source = this;
}
public override void Dispose()
{
- string path = GetFilePath();
- ProjectInfo info = ProjectInfo.FindProject(path);
-
- if (info != null)
- info.RemoveSource(this);
+ if (_projectInfo != null)
+ _projectInfo.RemoveSource(this);
base.Dispose();
}
+ #endregion
+
+ #region Properties
+
+ private ScopeCreatorCallback _scopeCreator;
+ public ScopeCreatorCallback ScopeCreator
+ {
+ get { return _scopeCreator; }
+ set { _scopeCreator = value; }
+ }
+
+ private int _timeStamp;
+ public int TimeStamp
+ {
+ get { return _timeStamp; }
+ }
+
+ private ProjectInfo _projectInfo;
+ public ProjectInfo ProjectInfo
+ {
+ get { return _projectInfo; }
+ }
+
+ private int _fileIndex = -1;
+ public int FileIndex
+ {
+ get { return _fileIndex; }
+ set { _fileIndex = value; }
+ }
+
+ #endregion
+
public override CommentInfo GetCommentFormat()
{
CommentInfo commentInfo = new CommentInfo();
@@ -55,26 +96,11 @@
return commentInfo;
}
- // _scopeCreator is never created or assigned. Probably it should be removed.
- //
- private ScopeCreatorCallback _scopeCreator;
- public ScopeCreatorCallback ScopeCreator
- {
- get { return _scopeCreator; }
- set { _scopeCreator = value; }
- }
-
public override void Completion(IVsTextView textView, TokenInfo info, ParseReason reason)
{
base.Completion(textView, info, reason);
}
- private int _timeStamp;
- public int TimeStamp
- {
- get { return _timeStamp; }
- }
-
public override void OnChangeLineText(TextLineChange[] lineChange, int last)
{
_timeStamp++;
More information about the svn
mailing list