Skip to content

Commit aeb690e

Browse files
author
dinov
committed
FI to Node.js branch
1 parent ee3ec03 commit aeb690e

File tree

412 files changed

+49640
-1674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

412 files changed

+49640
-1674
lines changed

Build/AssemblyInfoCommon.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
using System.Runtime.CompilerServices;
77
using System.Runtime.InteropServices;
88

9-
// The following assembly information is common to all * Tools for Visual Studio assemblies.
9+
// The following assembly information is common to all Python Tools for Visual
10+
// Studio assemblies.
1011
// If you get compiler errors CS0579, "Duplicate '<attributename>' attribute", check your
1112
// Properties\AssemblyInfo.cs file and remove any lines duplicating the ones below.
1213
// (See also AssemblyVersion.cs in this same directory.)
1314
[assembly: AssemblyCompany("Microsoft")]
14-
#if NODEJS_TOOLS
15-
[assembly: AssemblyProduct("Node.js Tools for Visual Studio")]
16-
#else
1715
[assembly: AssemblyProduct("Python Tools for Visual Studio")]
18-
[assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
16+
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
1917
[assembly: AssemblyTrademark("")]
2018
[assembly: AssemblyCulture("")]
21-
#endif

Build/Common.Build.CSharp.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<PropertyGroup>
1212
<Language>C#</Language> <!-- Duplicated from the C# targets file -->
13-
<Platform Condition="'$(Platform)'==''">AnyCPU</Platform>
13+
<Platform Condition="'$(Platform)'==''">x86</Platform>
1414

1515
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
1616
<!-- This eliminates the warning CA0060, EnvDTE Version=7.0 not found, for VS 10 installations. -->

Build/Common.Build.Wix.settings

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
<PropertyGroup>
1313
<Language>WiX</Language>
14-
<WixToolsVersion Condition="'$(WixToolsVersion)'==''">3.5</WixToolsVersion>
14+
<WixToolsVersion Condition="'$(WixToolsVersion)'==''">3.7</WixToolsVersion>
1515
<WixToolPath Condition="'$(WixToolPath)'==''">$(BuildRoot)\Tools\Wix\$(WixToolsVersion)</WixToolPath>
1616
<WixExtDir Condition="'$(WixExtDir)'==''">$(BuildRoot)\Tools\Wix\$(WixToolsVersion)</WixExtDir>
17-
<WixTargetsPath>$(WixToolPath)\Targets\Wix.targets</WixTargetsPath>
18-
<WixTasksPath>$(WixToolPath)\Targets\WixTasks.dll</WixTasksPath>
19-
<LuxTargetsPath>$(WixToolPath)\Targets\Lux.targets</LuxTargetsPath>
20-
<LuxTasksPath>$(WixToolPath)\Targets\LuxTasks.dll</LuxTasksPath>
17+
<WixTargetsPath>$(WixToolPath)\Wix.targets</WixTargetsPath>
18+
<WixTasksPath>$(WixToolPath)\WixTasks.dll</WixTasksPath>
19+
<LuxTargetsPath>$(WixToolPath)\Lux.targets</LuxTargetsPath>
20+
<LuxTasksPath>$(WixToolPath)\LuxTasks.dll</LuxTasksPath>
2121
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
2222
</PropertyGroup>
2323

Build/Common.Build.settings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
<PropertyGroup>
1313
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
14-
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
1514
<WixVersion Condition="$(WixVersion)==''">0.7.4100.000</WixVersion>
1615
<!--Default Platform value is specified in the C#/C++ specific files imported below -->
1716

@@ -60,6 +59,11 @@
6059
<DevEnvDir Condition="'$(VSTarget)'=='10.0'">$(VS100COMNTOOLS)..\IDE\</DevEnvDir>
6160
<DevEnvDir Condition="'$(VSTarget)'=='11.0'">$(VS110COMNTOOLS)..\IDE\</DevEnvDir>
6261
<DevEnvDir Condition="'$(VSTarget)'=='12.0'">$(VS120COMNTOOLS)..\IDE\</DevEnvDir>
62+
63+
<VSSDKDir Condition="'$(VSTarget)'=='10.0'">$(VSSDK100Install)</VSSDKDir>
64+
<VSSDKDir Condition="'$(VSTarget)'=='11.0'">$(VSSDK110Install)</VSSDKDir>
65+
<VSSDKDir Condition="'$(VSTarget)'=='12.0'">$(VSSDK120Install)</VSSDKDir>
66+
6367
</PropertyGroup>
6468

6569
<Import Project="$(TargetsPath)\Common.Build.CSharp.settings" Condition="'$(MSBuildProjectExtension)' == '.csproj' or '$(MSBuildProjectExtension)' == '.tmp_proj'" />

Common/Product/ReplWindow/Repl/InlineReplAdornment.cs

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
*
1313
* ***************************************************************************/
1414

15-
using System;
16-
using System.Collections.Generic;
1715
using System.ComponentModel.Composition;
1816
using System.Windows;
19-
using System.Windows.Threading;
2017
using Microsoft.VisualStudio.Text;
2118
using Microsoft.VisualStudio.Text.Editor;
2219
using Microsoft.VisualStudio.Text.Tagging;
@@ -42,72 +39,23 @@ public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer) where
4239
);
4340
}
4441

45-
class InlineReplAdornmentManager : ITagger<IntraTextAdornmentTag> {
46-
private readonly ITextView _textView;
47-
private readonly List<Tuple<int, ZoomableInlineAdornment>> _tags;
48-
private readonly Dispatcher _dispatcher;
49-
50-
internal InlineReplAdornmentManager(ITextView textView) {
51-
_textView = textView;
52-
_tags = new List<Tuple<int, ZoomableInlineAdornment>>();
53-
_dispatcher = Dispatcher.CurrentDispatcher;
54-
}
55-
56-
public IEnumerable<ITagSpan<IntraTextAdornmentTag>> GetTags(NormalizedSnapshotSpanCollection spans) {
57-
var result = new List<TagSpan<IntraTextAdornmentTag>>();
58-
foreach (var t in _tags) {
59-
var span = new SnapshotSpan(_textView.TextSnapshot, t.Item1, 0);
60-
t.Item2.UpdateSize();
61-
var tag = new IntraTextAdornmentTag(t.Item2, null);
62-
result.Add(new TagSpan<IntraTextAdornmentTag>(span, tag));
63-
}
64-
return result;
65-
}
66-
67-
public void AddAdornment(ZoomableInlineAdornment uiElement) {
68-
if (Dispatcher.CurrentDispatcher != _dispatcher) {
69-
_dispatcher.BeginInvoke(new Action(() => AddAdornment(uiElement)));
70-
return;
71-
}
72-
var caretPos = _textView.Caret.Position.BufferPosition;
73-
var caretLine = caretPos.GetContainingLine();
74-
_tags.Add(new Tuple<int, ZoomableInlineAdornment>(caretPos.Position, uiElement));
75-
var handler = TagsChanged;
76-
if (handler != null) {
77-
var span = new SnapshotSpan(_textView.TextSnapshot, caretLine.Start, caretLine.Length);
78-
var args = new SnapshotSpanEventArgs(span);
79-
handler(this, args);
80-
}
81-
}
82-
83-
public IList<Tuple<int, ZoomableInlineAdornment>> Adornments {
84-
get { return _tags; }
85-
}
86-
87-
public void RemoveAll() {
88-
_tags.Clear();
89-
}
90-
91-
public event EventHandler<SnapshotSpanEventArgs> TagsChanged;
92-
93-
}
94-
95-
private static InlineReplAdornmentManager GetManager(ITextView view) {
42+
internal static InlineReplAdornmentManager GetManager(ITextView view) {
9643
InlineReplAdornmentManager result;
9744
if (!view.Properties.TryGetProperty<InlineReplAdornmentManager>(typeof(InlineReplAdornmentManager), out result)) {
9845
return null;
9946
}
10047
return result;
10148
}
10249

103-
public static void AddInlineAdornment(ITextView view, UIElement uiElement, RoutedEventHandler onLoaded) {
50+
public static void AddInlineAdornment(ITextView view, UIElement uiElement, RoutedEventHandler onLoaded, SnapshotPoint targetLoc) {
10451
var manager = GetManager(view);
10552
if (manager != null) {
10653
var adornment = new ZoomableInlineAdornment(uiElement, view);
107-
// Original Python code unhooked this event after load was complete
108-
// I don't think this should be needed... we'll see.
54+
// Event is unhooked in ReplWindow. If we don't we'll receive the event multiple
55+
// times leading to very jerky / hang like behavior where we've setup a new event
56+
// loop in the repl window.
10957
adornment.Loaded += onLoaded;
110-
manager.AddAdornment(adornment);
58+
manager.AddAdornment(adornment, targetLoc);
11159
}
11260
}
11361

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* ****************************************************************************
2+
*
3+
* Copyright (c) Microsoft Corporation.
4+
*
5+
* This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6+
* copy of the license can be found in the License.html file at the root of this distribution. If
7+
* you cannot locate the Apache License, Version 2.0, please send an email to
8+
* [email protected]. By using this source code in any fashion, you are agreeing to be bound
9+
* by the terms of the Apache License, Version 2.0.
10+
*
11+
* You must not remove this notice, or any other, from this software.
12+
*
13+
* ***************************************************************************/
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Windows.Threading;
18+
using Microsoft.VisualStudio.Text;
19+
using Microsoft.VisualStudio.Text.Editor;
20+
using Microsoft.VisualStudio.Text.Tagging;
21+
22+
#if NTVS_FEATURE_INTERACTIVEWINDOW
23+
namespace Microsoft.NodejsTools.Repl {
24+
#else
25+
namespace Microsoft.VisualStudio.Repl {
26+
#endif
27+
class InlineReplAdornmentManager : ITagger<IntraTextAdornmentTag> {
28+
private readonly ITextView _textView;
29+
private readonly List<Tuple<SnapshotPoint, ZoomableInlineAdornment>> _tags;
30+
private readonly Dispatcher _dispatcher;
31+
32+
internal InlineReplAdornmentManager(ITextView textView) {
33+
_textView = textView;
34+
_tags = new List<Tuple<SnapshotPoint, ZoomableInlineAdornment>>();
35+
_dispatcher = Dispatcher.CurrentDispatcher;
36+
}
37+
38+
public IEnumerable<ITagSpan<IntraTextAdornmentTag>> GetTags(NormalizedSnapshotSpanCollection spans) {
39+
var result = new List<TagSpan<IntraTextAdornmentTag>>();
40+
for (int i = 0; i < _tags.Count; i++) {
41+
if (_tags[i].Item1.Snapshot != _textView.TextSnapshot) {
42+
// update to the latest snapshot
43+
_tags[i] = new Tuple<SnapshotPoint, ZoomableInlineAdornment>(
44+
_tags[i].Item1.TranslateTo(_textView.TextSnapshot, PointTrackingMode.Negative),
45+
_tags[i].Item2
46+
);
47+
}
48+
49+
var span = new SnapshotSpan(_textView.TextSnapshot, _tags[i].Item1, 0);
50+
bool intersects = false;
51+
foreach (var applicableSpan in spans) {
52+
if (applicableSpan.TranslateTo(_textView.TextSnapshot, SpanTrackingMode.EdgeInclusive).IntersectsWith(span)) {
53+
intersects = true;
54+
break;
55+
}
56+
}
57+
if (!intersects) {
58+
continue;
59+
}
60+
var tag = new IntraTextAdornmentTag(_tags[i].Item2, null);
61+
result.Add(new TagSpan<IntraTextAdornmentTag>(span, tag));
62+
}
63+
return result;
64+
}
65+
66+
public void AddAdornment(ZoomableInlineAdornment uiElement, SnapshotPoint targetLoc) {
67+
if (Dispatcher.CurrentDispatcher != _dispatcher) {
68+
_dispatcher.BeginInvoke(new Action(() => AddAdornment(uiElement, targetLoc)));
69+
return;
70+
}
71+
var targetLine = targetLoc.GetContainingLine();
72+
_tags.Add(new Tuple<SnapshotPoint, ZoomableInlineAdornment>(targetLoc, uiElement));
73+
var handler = TagsChanged;
74+
if (handler != null) {
75+
var span = new SnapshotSpan(_textView.TextSnapshot, targetLine.Start, targetLine.LengthIncludingLineBreak);
76+
var args = new SnapshotSpanEventArgs(span);
77+
handler(this, args);
78+
}
79+
}
80+
81+
public IList<Tuple<SnapshotPoint, ZoomableInlineAdornment>> Adornments {
82+
get { return _tags; }
83+
}
84+
85+
public void RemoveAll() {
86+
_tags.Clear();
87+
}
88+
89+
public event EventHandler<SnapshotSpanEventArgs> TagsChanged;
90+
}
91+
}

Common/Product/ReplWindow/Repl/ReplWindow.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class ReplWindow : ToolWindowPane, IOleCommandTarget, IReplWindow, IVsFindTarget
161161
//
162162
private readonly OutputBuffer _buffer;
163163
private readonly List<ColoredSpan> _outputColors = new List<ColoredSpan>();
164+
private bool _addedLineBreakOnLastOutput;
164165

165166
private string _commandPrefix = "%";
166167
private string _prompt = "» "; // prompt for primary input
@@ -638,7 +639,7 @@ private void ClearScreen(bool insertInputPrompt) {
638639
edit.Delete(0, _outputBuffer.CurrentSnapshot.Length);
639640
edit.Apply();
640641
}
641-
642+
_addedLineBreakOnLastOutput = false;
642643
using (var edit = _stdInputBuffer.CreateEdit(EditOptions.None, null, SuppressPromptInjectionTag)) {
643644
edit.Delete(0, _stdInputBuffer.CurrentSnapshot.Length);
644645
edit.Apply();
@@ -1016,7 +1017,9 @@ private void Home(bool extendSelection) {
10161017
PositionAffinity.Successor,
10171018
_projectionBuffer
10181019
);
1019-
Debug.Assert(projectionPoint != null);
1020+
if (projectionPoint == null) {
1021+
throw new InvalidOperationException("Could not map langLine to buffer");
1022+
}
10201023

10211024
//
10221025
// If the caret is already at the first non-whitespace character or
@@ -1073,7 +1076,9 @@ private void End(bool extendSelection) {
10731076
PositionAffinity.Successor,
10741077
_projectionBuffer
10751078
);
1076-
Debug.Assert(projectionPoint != null);
1079+
if (projectionPoint == null) {
1080+
throw new InvalidOperationException("Could not map langLine to buffer");
1081+
}
10771082

10781083
var moveTo = projectionPoint.Value;
10791084

@@ -2150,11 +2155,23 @@ internal void AppendOutput(ConsoleColor color, string text, bool lastOutput) {
21502155
// append the text to output buffer and make sure it ends with a line break:
21512156
int newOutputLength = text.Length;
21522157
using (var edit = _outputBuffer.CreateEdit()) {
2158+
if (_addedLineBreakOnLastOutput) {
2159+
// appending additional output, remove the line break we previously injected
2160+
var lineBreak = GetLineBreak();
2161+
var deleteSpan = new Span(_outputBuffer.CurrentSnapshot.Length - lineBreak.Length, lineBreak.Length);
2162+
Debug.Assert(_outputBuffer.CurrentSnapshot.GetText(deleteSpan) == lineBreak);
2163+
edit.Delete(deleteSpan);
2164+
oldBufferLength -= lineBreak.Length;
2165+
}
2166+
21532167
edit.Insert(oldBufferLength, text);
21542168
if (lastOutput && !_readingStdIn && !EndsWithLineBreak(text)) {
21552169
var lineBreak = GetLineBreak();
21562170
edit.Insert(oldBufferLength, lineBreak);
21572171
newOutputLength += lineBreak.Length;
2172+
_addedLineBreakOnLastOutput = true;
2173+
} else {
2174+
_addedLineBreakOnLastOutput = false;
21582175
}
21592176

21602177
edit.Apply();
@@ -2231,7 +2248,35 @@ private bool TryShowObject(object obj) {
22312248
UIElement element = obj as UIElement;
22322249
if (element != null) {
22332250
_buffer.Flush();
2234-
InlineReplAdornmentProvider.AddInlineAdornment(TextView, element, OnAdornmentLoaded);
2251+
2252+
// figure out where we're inserting the image
2253+
SnapshotPoint targetPoint = new SnapshotPoint(
2254+
TextView.TextBuffer.CurrentSnapshot,
2255+
TextView.TextBuffer.CurrentSnapshot.Length
2256+
);
2257+
2258+
for (int i = _projectionSpans.Count - 1; i >= 0; i--) {
2259+
if (_projectionSpans[i].Kind == ReplSpanKind.Output ||
2260+
(_projectionSpans[i].Kind == ReplSpanKind.Language && _isRunning)) {
2261+
// we've had some output during the execution and we hit that buffer.
2262+
// OR we hit a language input buffer, and we're running, and no output
2263+
// has been produced yet.
2264+
2265+
// In either case, this is where the image goes.
2266+
break;
2267+
}
2268+
2269+
// adjust where we're going to insert based upon the length of the span
2270+
targetPoint -= _projectionSpans[i].Length;
2271+
2272+
if (_projectionSpans[i].Kind == ReplSpanKind.Prompt) {
2273+
// we just walked past the primary input prompt, we want to put the
2274+
// image right before it.
2275+
break;
2276+
}
2277+
}
2278+
2279+
InlineReplAdornmentProvider.AddInlineAdornment(TextView, element, OnAdornmentLoaded, targetPoint);
22352280
OnInlineAdornmentAdded();
22362281
WriteLine(String.Empty);
22372282
WriteLine(String.Empty);
@@ -2242,6 +2287,7 @@ private bool TryShowObject(object obj) {
22422287
}
22432288

22442289
private void OnAdornmentLoaded(object source, EventArgs e) {
2290+
((ZoomableInlineAdornment)source).Loaded -= OnAdornmentLoaded;
22452291
// Make sure the caret line is rendered
22462292
DoEvents();
22472293
Caret.EnsureVisible();

Common/Product/ReplWindow/Repl/ReplWindowProvider.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public IReplWindow CreateReplWindow(IContentType contentType, string/*!*/ title,
6060
foreach (var provider in _evaluators) {
6161
var evaluator = provider.GetEvaluator(replId);
6262
if (evaluator != null) {
63-
string[] roles = provider.GetType().GetCustomAttributes(typeof(ReplRoleAttribute), true).Select(r => ((ReplRoleAttribute)r).Name).ToArray();
63+
string[] roles = evaluator.GetType().GetCustomAttributes(typeof(ReplRoleAttribute), true).Select(r => ((ReplRoleAttribute)r).Name).ToArray();
6464
window = CreateReplWindowInternal(evaluator, contentType, roles, curId, title, languageServiceGuid, replId);
6565
if ((null == window) || (null == window.Frame)) {
6666
throw new NotSupportedException(Resources.CanNotCreateWindow);
@@ -93,7 +93,7 @@ private static IReplEvaluator GetReplEvaluator(IComponentModel model, string rep
9393
var evaluator = provider.GetEvaluator(replId);
9494

9595
if (evaluator != null) {
96-
roles = provider.GetType().GetCustomAttributes(typeof(ReplRoleAttribute), true).Select(r => ((ReplRoleAttribute)r).Name).ToArray();
96+
roles = evaluator.GetType().GetCustomAttributes(typeof(ReplRoleAttribute), true).Select(r => ((ReplRoleAttribute)r).Name).ToArray();
9797
return evaluator;
9898
}
9999
}
@@ -216,9 +216,13 @@ private ReplWindow CreateReplWindowInternal(IReplEvaluator evaluator, IContentTy
216216
// we don't pass __VSCREATETOOLWIN.CTW_fMultiInstance because multi instance panes are
217217
// destroyed when closed. We are really multi instance but we don't want to be closed. This
218218
// seems to work fine.
219+
var creationFlags = __VSCREATETOOLWIN.CTW_fInitNew;
220+
if (!roles.Contains("DontPersist")) {
221+
creationFlags |= __VSCREATETOOLWIN.CTW_fForceCreate;
222+
}
219223
ErrorHandler.ThrowOnFailure(
220224
service.CreateToolWindow(
221-
(uint)(__VSCREATETOOLWIN.CTW_fInitNew | __VSCREATETOOLWIN.CTW_fForceCreate),
225+
(uint)(creationFlags),
222226
(uint)id,
223227
replWindow.GetIVsWindowPane(),
224228
ref clsId,

0 commit comments

Comments
 (0)