Skip to content

Commit a88ae79

Browse files
author
Charlie Barto
committed
more work on squiggles, trying to fix suggestions for subfolders and failing
1 parent bccb67d commit a88ae79

File tree

8 files changed

+191
-11
lines changed

8 files changed

+191
-11
lines changed

LibNimrod/NimrodSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Reference Include="System.Xml" />
6565
</ItemGroup>
6666
<ItemGroup>
67+
<Compile Include="checker.cs" />
6768
<Compile Include="highlite.cs" />
6869
<Compile Include="idetools.cs" />
6970
<Compile Include="lexer.cs" />

LibNimrod/checker.cs

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.IO;
5+
using System.Diagnostics;
6+
using System.Threading.Tasks;
7+
using System.Text.RegularExpressions;
8+
9+
namespace NimrodSharp
10+
{
11+
public enum errTypes
12+
{
13+
unknown,
14+
XDeclaredButNotUsed
15+
}
16+
public enum CheckReplyType
17+
{
18+
Hint,
19+
Warning,
20+
Error,
21+
Fatal,
22+
Unknown
23+
}
24+
public class CheckReply
25+
{
26+
public CheckReplyType type;
27+
public errTypes message;
28+
public string messageString;
29+
public string filePath;
30+
public int row;
31+
public int col;
32+
public int rowend;
33+
public int colend;
34+
35+
}
36+
public static class checkfuncs
37+
{
38+
private static string findIdentifier(string message)
39+
{
40+
var firstidx = message.IndexOf('\'');
41+
var lastidx = message.IndexOf('\'', firstidx + 1);
42+
var ident = message.Substring(firstidx + 1, lastidx - firstidx - 1);
43+
var dotidx = ident.IndexOf('.');
44+
if (dotidx != -1)
45+
{
46+
ident = ident.Substring(dotidx);
47+
}
48+
return ident;
49+
}
50+
private static ProcessStartInfo CreateStartInfo(string filename, string rootDir)
51+
{
52+
ProcessStartInfo rv = new ProcessStartInfo("nimrod");
53+
rv.WorkingDirectory = rootDir;
54+
rv.Arguments = "--path:" + rootDir + " --verbosity:0 check " + filename;
55+
rv.WorkingDirectory = Path.GetDirectoryName(filename);
56+
rv.CreateNoWindow = true;
57+
rv.UseShellExecute = false;
58+
rv.RedirectStandardError = true;
59+
rv.RedirectStandardInput = true;
60+
rv.RedirectStandardOutput = true;
61+
return rv;
62+
}
63+
private static void addEndInformation(CheckReply reply)
64+
{
65+
switch (reply.message)
66+
{
67+
case errTypes.unknown:
68+
break;
69+
case errTypes.XDeclaredButNotUsed:
70+
var ident = findIdentifier(reply.messageString);
71+
reply.colend = reply.colend + ident.Length;
72+
break;
73+
default:
74+
break;
75+
}
76+
}
77+
private static CheckReply ParseLine(Match match, string rootDir)
78+
{
79+
CheckReply rv = new CheckReply();
80+
rv.filePath = match.Groups[1].Value;
81+
if (!Path.IsPathRooted(rv.filePath))
82+
{
83+
rv.filePath = Path.Combine(rootDir, rv.filePath);
84+
}
85+
rv.row = int.Parse(match.Groups[2].Value) - 1;
86+
rv.col = int.Parse(match.Groups[3].Value);
87+
rv.rowend = rv.row;
88+
rv.colend = rv.col + 1;
89+
if (match.Groups[4].Value == "Hint")
90+
{
91+
rv.type = CheckReplyType.Warning;
92+
}
93+
else if (match.Groups[4].Value == "Error")
94+
{
95+
rv.type = CheckReplyType.Error;
96+
}
97+
else
98+
{
99+
rv.type = CheckReplyType.Unknown;
100+
}
101+
var result = Enum.TryParse<errTypes>(match.Groups[6].Value, out rv.message);
102+
if (!result)
103+
{
104+
rv.message = errTypes.unknown;
105+
}
106+
rv.messageString = match.Groups[5].Value;
107+
addEndInformation(rv);
108+
return rv;
109+
}
110+
111+
private static IEnumerable<CheckReply> ParseReply(string reply, string rootDir)
112+
{
113+
var rv = new List<CheckReply>();
114+
var regex = new Regex(@"(.+\.nim)\((\d+), (\d+)\) (.+?): (.+) \[(.+)\]");
115+
116+
var matches = regex.Matches(reply);
117+
foreach (Match match in matches)
118+
{
119+
rv.Add(ParseLine(match, rootDir));
120+
}
121+
return rv;
122+
}
123+
124+
125+
public static IEnumerable<CheckReply> CheckFile(string filename, string projectRoot)
126+
{
127+
var startInfo = CreateStartInfo(filename, projectRoot);
128+
startInfo.WorkingDirectory = projectRoot;
129+
var proc = Process.Start(startInfo);
130+
string result = proc.StandardOutput.ReadToEnd();
131+
proc.WaitForExit();
132+
return ParseReply(result, Path.GetDirectoryName(filename));
133+
}
134+
}
135+
}

LibNimrod/idetools.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ public static List<idetoolsReply> ParseMultipleReply(string reply)
114114
public static string GetArgs(string action, string file, int line, int col, string project)
115115
{
116116
string fileRelitive = file.Substring(Path.GetDirectoryName(project).Length + 1);
117-
string rv = "--verbosity:0 idetools --track:" + fileRelitive + "," + (line + 1).ToString() + "," + col.ToString() + " --" + action + " " + Path.GetFileName(project);
117+
var projectDir = Path.GetDirectoryName(project);
118+
string rv = "--verbosity:0 --path:"+projectDir + " idetools --track:" + fileRelitive + "," + (line + 1).ToString() + "," + col.ToString() + " --" + action + " " + Path.GetFileName(project);
118119
return rv;
119120
}
120121
public static string GetDirtyArgs(string action, string dirty_file, string file, int line, int col, string project)
121122
{
122123
string fileRelitive = file.Substring(Path.GetDirectoryName(project).Length + 1);
123-
string rv = " --verbosity:0 idetools --trackDirty:\"" + dirty_file + "," + fileRelitive + "," + line.ToString() + "," + col.ToString() + "\" --" + action + " " + Path.GetFileName(project);
124+
var projectDir = Path.GetDirectoryName(project);
125+
string rv = " --verbosity:0 --path:"+projectDir+" idetools --trackDirty:" + dirty_file + "," + fileRelitive + "," + line.ToString() + "," + col.ToString() + " --" + action + " " + Path.GetFileName(project);
124126
return rv;
125127
}
126128
public static string GetRawResults(string action, string file, int line, int col, string project)

NimrodVS/NimrodAuthoringScope.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,32 @@
1111
using Microsoft.VisualStudio.Project;
1212
using Microsoft.VisualStudio;
1313
using EnvDTE;
14+
using System.Runtime.InteropServices;
1415
namespace Company.NimrodVS
1516
{
1617
public class NimrodAuthoringScope : AuthoringScope
1718
{
1819
private string m_filename;
1920
private string m_dirtyname;
2021
private string m_projectfile;
21-
22-
public NimrodAuthoringScope(string filename, string dirtyname, string projectfile) : base()
22+
private AuthoringSink m_sink;
23+
public NimrodAuthoringScope(AuthoringSink sink, string filename, string dirtyname, string projectfile) : base()
2324
{
25+
m_sink = sink;
2426
m_filename = filename;
2527
m_dirtyname = dirtyname;
2628
m_projectfile = projectfile;
29+
30+
}
31+
public NimrodAuthoringScope(ParseRequest req, string dirtyFile, string project)
32+
: base()
33+
{
34+
m_sink = req.Sink;
35+
m_projectfile = project;
36+
m_dirtyname = dirtyFile;
37+
m_filename = req.FileName;
2738
}
39+
2840
public override string GetDataTipText(int line, int col, out TextSpan span)
2941
{
3042
span = new TextSpan();
@@ -34,13 +46,23 @@ public override string GetDataTipText(int line, int col, out TextSpan span)
3446
public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
3547
{
3648
string text;
37-
view.GetTextStream(0, 0, line, col, out text);
49+
int numLines;
50+
int lastCol;
51+
IVsTextLines buf = null;
52+
var hr = view.GetBuffer(out buf);
53+
Marshal.ThrowExceptionForHR(hr);
54+
hr = buf.GetLineCount(out numLines);
55+
Marshal.ThrowExceptionForHR(hr);
56+
hr = buf.GetLengthOfLine(numLines - 1, out lastCol);
57+
Marshal.ThrowExceptionForHR(hr);
58+
hr = buf.GetLineText(0, 0, numLines - 1, lastCol, out text);
59+
Marshal.ThrowExceptionForHR(hr);
3860
File.WriteAllText(m_dirtyname, text, new UTF8Encoding(false));
3961
switch (reason)
4062
{
4163
case ParseReason.CompleteWord:
4264
case ParseReason.MemberSelect:
43-
var reply = idetoolsfuncs.GetDirtySuggestions(m_dirtyname, m_filename, line + 1, col + 1, m_filename);
65+
var reply = idetoolsfuncs.GetDirtySuggestions(m_dirtyname, m_filename, line + 1, col + 1, m_projectfile);
4466
return new IntelliSense.NimrodDeclarations(reply);
4567
default:
4668
return null;

NimrodVS/NimrodLanguageService.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public override Colorizer GetColorizer(IVsTextLines buffer)
6060
{
6161
return new Colorizer(this, buffer, GetScanner(buffer));
6262
}
63+
6364
public override AuthoringScope ParseSource(ParseRequest req)
6465
{
6566
var dte = (DTE)GetService(typeof(DTE));
@@ -68,7 +69,23 @@ public override AuthoringScope ParseSource(ParseRequest req)
6869
var node = props.Node as ManagedNimrodProject.NimrodProjectNode;
6970

7071
string startupObj = Path.Combine(node.ProjectFolder, node.GetProjectProperty("StartupObject"));
71-
return new NimrodAuthoringScope(req.FileName, m_dirtyfile, startupObj);
72+
if (req.Reason == ParseReason.Check)
73+
{
74+
var errors = NimrodSharp.checkfuncs.CheckFile(req.FileName, node.ProjectFolder);
75+
foreach (var error in errors)
76+
{
77+
TextSpan ctx;
78+
ctx.iStartLine = error.row;
79+
ctx.iEndLine = error.rowend;
80+
ctx.iStartIndex = error.col;
81+
ctx.iEndIndex = error.colend;
82+
if (error.filePath == req.FileName)
83+
{
84+
req.Sink.AddError(error.filePath, error.messageString, ctx, (Severity)error.type);
85+
}
86+
}
87+
}
88+
return new NimrodAuthoringScope(req, m_dirtyfile, startupObj);
7289
}
7390

7491
public override string GetFormatFilterList()

NimrodVS/NimrodSource.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ namespace Company.NimrodVS
1010
{
1111
public class NimrodSource : Source
1212
{
13-
public NimrodSource(LanguageService service, IVsTextLines buffer, Colorizer color) : base(service, buffer, color) { }
13+
public NimrodSource(LanguageService service, IVsTextLines buffer, Colorizer color) : base(service, buffer, color)
14+
{
15+
this.LastParseTime = 0;
16+
}
17+
1418
public override void ReformatSpan(EditArray mgr, Microsoft.VisualStudio.TextManager.Interop.TextSpan span)
1519
{
1620
base.ReformatSpan(mgr, span);

NimrodVS/NimrodVSPackage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ namespace Company.NimrodVS
3838
[ProvideObject(typeof(BuildPropertyPage))]
3939
[ProvideService(typeof(NimrodLanguageService), ServiceName="Nimrod Language Service")]
4040
[ProvideLanguageService(typeof(NimrodLanguageService), "Nimrod", 106, CodeSense=true, EnableFormatSelection = true,
41-
RequestStockColors=true)]
41+
RequestStockColors=true, DefaultToInsertSpaces=true)]
4242
[ProvideLanguageExtension(typeof(NimrodLanguageService), ".nim")]
4343
[ProvideProjectFactory(typeof(ManagedNimrodProject.NimrodProjectFactory), null, "Nimrod Projects (*.nimproj);*.nimproj", "nimproj", "nimproj", ".\\NullPath", LanguageVsTemplate = "NimrodProject", NewProjectRequireNewFolderVsTemplate=false)]
44-
//[ProvideProjectItem(typeof(ManagedNimrodProject.NimrodProjectFactory), "Nimrod Source", @"..\..\Templates\ProjectItems\NimrodProject", 500)]
4544
public sealed class NimrodVSPackage : ProjectPackage, IOleComponent
4645
{
4746
/// <summary>

NimrodVS/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<DisplayName>NimrodVS</DisplayName>
66
<Description xml:space="preserve">Adds nimrod support to visual studio</Description>
77
</Metadata>
8-
<Installation AllUsers="true">
8+
<Installation>
99
<InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[12.0]" />
1010
</Installation>
1111
<Dependencies>

0 commit comments

Comments
 (0)