Skip to content

Commit b1a4dd1

Browse files
committed
ops in progress
1 parent df8961e commit b1a4dd1

13 files changed

Lines changed: 169 additions & 55 deletions

.editorconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
[*]
1+
[*.cs]
22
indent_style = space
33
indent_size =4
4+
5+
[*.sls]
6+
indent_style = space
7+
indent_size =2

IronScheme.VisualStudio.REPL/CommandBuffer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class CommandBuffer
2020

2121
StringBuilder textSoFar;
2222
Stream textBufferStream;
23+
object env;
2324

2425
public CommandBuffer(Stream textBufferStream)
2526
{
@@ -32,6 +33,11 @@ public CommandBuffer(Stream textBufferStream)
3233

3334
public void Add(string text)
3435
{
36+
if (env is null)
37+
{
38+
env = "(new-interaction-environment)".Eval();
39+
}
40+
3541
// This function is called to add a line, so write a new line delimeter to the output.
3642
Write(System.Environment.NewLine);
3743

@@ -57,7 +63,7 @@ public void Add(string text)
5763
try
5864
{
5965
var output = new System.IO.StreamWriter(textBufferStream);
60-
var result = "(parameterize [(current-output-port {1})] (eval {0} (interaction-environment)))".Eval(expr, output);
66+
var result = "(parameterize [(current-output-port {1})] (eval {0} {2}))".Eval(expr, output, env);
6167
output.Flush();
6268
if (!Builtins.IsTrue(Builtins.IsUnspecified(result)))
6369
{

IronScheme.VisualStudio.REPL/ConsoleWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ protected override void Initialize()
128128
var options = adapterFactory.GetWpfTextView(textView).Options;
129129
options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false);
130130
options.SetOptionValue(DefaultTextViewOptions.AutoScrollId, true);
131+
options.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStyles.AutoIndent);
132+
131133

132134
adapterFactory.GetWpfTextView(textView).Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length));
133135

IronScheme.VisualStudio.REPL/IronScheme.VisualStudio.REPL.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@
101101
<DesignTime>True</DesignTime>
102102
<DependentUpon>Resources.resx</DependentUpon>
103103
</Compile>
104+
<Compile Include="Shell.cs" />
104105
<Compile Include="source.extension.cs">
105106
<AutoGen>True</AutoGen>
106107
<DesignTime>True</DesignTime>
107108
<DependentUpon>source.extension.vsixmanifest</DependentUpon>
108109
</Compile>
109110
<Compile Include="TextBufferStream.cs" />
111+
<Compile Include="TextViewCreationListener.cs" />
110112
</ItemGroup>
111113
<ItemGroup>
112114
<VSCTCompile Include="SchemeConsole.vsct">
@@ -122,6 +124,11 @@
122124
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
123125
<IncludeInVSIX>true</IncludeInVSIX>
124126
</Content>
127+
<Content Include="..\IronScheme.VisualStudio\editor.sls">
128+
<Link>editor.sls</Link>
129+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
130+
<IncludeInVSIX>true</IncludeInVSIX>
131+
</Content>
125132
<None Include="source.extension.vsixmanifest">
126133
<Generator>VsixManifestGenerator</Generator>
127134
<LastGenOutput>source.extension.cs</LastGenOutput>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text.RegularExpressions;
6+
using IronScheme.Runtime;
7+
using IronScheme.Scripting;
8+
using Microsoft.VisualStudio.Text;
9+
using Microsoft.VisualStudio.Text.Editor;
10+
using Microsoft.VisualStudio.Text.Operations;
11+
12+
namespace IronScheme.VisualStudio
13+
{
14+
public static class Shell
15+
{
16+
public static IEditorOperationsFactoryService EditorOperationsFactoryService { get; internal set; }
17+
internal static Dictionary<string, ITextView> Views { get; } = new Dictionary<string, ITextView>();
18+
19+
public static Cons OpenViews() => Cons.FromList(Views.Keys);
20+
21+
public static void SetView(string filename)
22+
{
23+
if (Views.TryGetValue(filename, out var view))
24+
{
25+
var ops = EditorOperationsFactoryService.GetEditorOperations(view);
26+
if (ops != null)
27+
{
28+
"(view {0})".Eval(ops);
29+
}
30+
}
31+
}
32+
33+
public static Cons GetOperations()
34+
{
35+
var methods = new List<Cons>();
36+
37+
var all = Methods<IEditorOperations>().Concat(Methods<IEditorOperations2>()).Concat(Methods<IEditorOperations3>());
38+
39+
foreach (var meth in all)
40+
{
41+
if (CanDealWithParams(meth))
42+
{
43+
var clrType = SymbolTable.StringToId(meth.DeclaringType.Name);
44+
var clrName = SymbolTable.StringToId(meth.Name);
45+
var name = Schemify(meth.Name.Replace("get_", ""));
46+
var args = Cons.FromList(meth.GetParameters().Select(x => Schemify(x.Name)));
47+
methods.Add(new Cons(clrType, new Cons(clrName, new Cons(name, args))));
48+
}
49+
}
50+
51+
return Cons.FromList(methods);
52+
53+
MethodInfo[] Methods<T>()
54+
{
55+
return typeof(T).GetMethods();
56+
}
57+
}
58+
59+
private static object Schemify(string name)
60+
{
61+
var newname = Regex.Replace(name, "[A-Z]", m => m.Index == 0 ? m.Value.ToLower() : ("-" + m.Value.ToLower()));
62+
return SymbolTable.StringToId(newname);
63+
}
64+
65+
66+
static HashSet<Type> safetypes = new HashSet<Type>()
67+
{
68+
typeof(string),
69+
typeof(bool),
70+
typeof(int),
71+
typeof(void)
72+
};
73+
74+
private static bool CanDealWithParams(System.Reflection.MethodInfo meth)
75+
{
76+
if (safetypes.Contains(meth.ReturnType))
77+
{
78+
var pars = meth.GetParameters();
79+
return pars.Length == 0 || pars.All(p => safetypes.Contains(p.ParameterType));
80+
}
81+
82+
return false;
83+
}
84+
}
85+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.ComponentModel.Composition;
2+
using Microsoft.VisualStudio.Text;
3+
using Microsoft.VisualStudio.Text.Editor;
4+
using Microsoft.VisualStudio.Utilities;
5+
6+
namespace IronScheme.VisualStudio
7+
{
8+
[Export(typeof(ITextViewCreationListener))]
9+
[ContentType("scheme")]
10+
[TextViewRole(PredefinedTextViewRoles.Document)]
11+
class TextViewCreationListener : ITextViewCreationListener
12+
{
13+
private readonly ITextDocumentFactoryService textDocumentFactory;
14+
15+
[ImportingConstructor]
16+
public TextViewCreationListener(ITextDocumentFactoryService textDocumentFactory, Microsoft.VisualStudio.Text.Operations.IEditorOperationsFactoryService editorOperationsFactoryService)
17+
{
18+
this.textDocumentFactory = textDocumentFactory;
19+
Shell.EditorOperationsFactoryService = editorOperationsFactoryService;
20+
}
21+
22+
public void TextViewCreated(ITextView textView)
23+
{
24+
if (textDocumentFactory.TryGetTextDocument(textView.TextBuffer, out var doc))
25+
{
26+
Shell.Views.Add(doc.FilePath, textView);
27+
textView.Closed += (s, e) => Shell.Views.Remove(doc.FilePath);
28+
}
29+
}
30+
}
31+
}

IronScheme.VisualStudio/Errors/ErrorTagger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void ReparseFile(object sender, EventArgs args)
272272
}
273273
}
274274

275-
tableDataSink.AddSnapshot(_snapshot, true);
275+
tableDataSink?.AddSnapshot(_snapshot, true);
276276

277277
RaiseTagsChanged(new SnapshotSpan(snapshot, 0, snapshot.Length));
278278
}

IronScheme.VisualStudio/IronScheme.VisualStudio.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
<Compile Include="BraceMatchingTagger.cs" />
9292
<Compile Include="BufferIdleEventUtil.cs" />
9393
<Compile Include="ClassificationTagger.cs" />
94-
<Compile Include="Shell.cs" />
9594
<Compile Include="Errors\ErrorTagger.cs" />
9695
<Compile Include="Errors\ErrorTaggerProvider.cs" />
9796
<Compile Include="AsyncTokenQuickInfoSource.cs" />
@@ -108,7 +107,6 @@
108107
</Compile>
109108
<Compile Include="Errors\ErrorsSnapshot.cs" />
110109
<Compile Include="StructureTagger.cs" />
111-
<Compile Include="TextViewCreationListener.cs" />
112110
</ItemGroup>
113111
<ItemGroup>
114112
<Content Include="..\IronScheme.VisualStudio.REPL\bin\Debug\IronScheme.VisualStudio.REPL.pkgdef">
@@ -150,6 +148,8 @@
150148
<ProjectReference Include="..\IronScheme.VisualStudio.REPL\IronScheme.VisualStudio.REPL.csproj">
151149
<Project>{2aea2177-08b0-4492-b911-ccea5b4c33a0}</Project>
152150
<Name>IronScheme.VisualStudio.REPL</Name>
151+
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup%3bBuiltProjectOutputGroupDependencies%3bGetCopyToOutputDirectoryItems%3bSatelliteDllsProjectOutputGroup%3b</IncludeOutputGroupsInVSIX>
152+
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIXLocalOnly>
153153
</ProjectReference>
154154
</ItemGroup>
155155
<ItemGroup>

IronScheme.VisualStudio/Shell.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

IronScheme.VisualStudio/TextViewCreationListener.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)