Watching TypeScript module vars in VS2013 - visual-studio-2013

In Visual Studio 2013 Update 2RC (TypeScript 1.0), although the following code works, if you set a breakpoint on age and hover over it, nothing appears. You have to watch Test.age.
But the code is correct, isn't it?
module Test
{
export var age: number;
export function go()
{
age = 40;
return age; // put a breakpoint here, and hover over age
}
}
Test.go();
Notice if you do not export age, the debugging works as expected!

The VS debugger and TypeScript source map emitter don't yet implement symbol mapping. To understand what's going on, look at the generated code:
var Test;
(function (Test) {
Test.age;
function go() {
Test.age = 40;
return Test.age;
}
Test.go = go;
})(Test || (Test = {}));
Test.go();
Note that there is no variable named age in scope at any point, only a property called age on the Test module.
Contrast this to the generated code to if you had removed export from age:
var Test;
(function (Test) {
var age;
function go() {
age = 40;
return age;
}
Test.go = go;
})(Test || (Test = {}));
Test.go();
Here, age does exist and the debugger can find it.

Related

There is a line above "List" and I get an error. How can i assign a clean "List"

void main() {
var urunler = new List(5);
urunler[0] = "Laptop";
urunler[1] = "Mouse";
urunler[2] = "Keyboard";
urunler[3] = "Monitor";
urunler[4] = "Mic";
print(urunler);
}
lib/main.dart:2:21: Error: Can't use the default List constructor. Try
using List.filled instead. var urunler = new List(5);
^ Failed to compile application.
The default 'List' constructor isn't available when null safety is
enabled.
Try this:
void main() {
var urunler = List<String>.filled(5,"",growable: false);
urunler[0] = "Laptop";
urunler[1] = "Mouse";
urunler[2] = "Keyboard";
urunler[3] = "Monitor";
urunler[4] = "Mic";
print(urunler);
}
https://api.dart.dev/stable/2.14.2/dart-core/List/List.filled.html
For a List, its better if you declare what kind of List you want to make. I dont think you can create a clean list because we need inital value for it, or you can create a blank list, and use a function to return the data inside. But from the code above, this is the best approach I can think right now.
List<String> urunler = ["Laptop", "Mouse", "Keyoboard"];

How to get IEditorOperations from IVsTextView?

I'm developing my first Visual Studio (2015 Community) Command Menu and I'm trying to get access to IEditorOperations to delete text, send backspace etc. but I'm not sure how to. I can do:
var Service = Provider.GetService(typeof(IEditorOperationsFactoryService)) as IEditorOperationsFactoryService;
Service.GetEditorOperations(???);
I'm not sure what to pass in the ??? since I don't have access to an ITextView instead what I have is a IVsTExtView via:
IVsTextView View;
IVsTextManager Manager = (IVsTextManager)ServiceProvider.GetService(typeof(SVsTextManager));
int MustHaveFocus = 1;
Manager.GetActiveView(MustHaveFocus, null, out View);
When creating the Command Menu, VS generates a template for me with a private ctor creating the command service, binding it to the command set id etc. An overridden Initialize method, and a bunch of properties.
Any ideas?
EDIT: After help from Sergey, I managed to get a bit further. But now I get a null when I try to get the IEditorOperationsFactoryService, all the other values are valid.
static IEditorOperations GetEditorService(IServiceProvider Provider, IVsTextView VsView)
{
IEditorOperations Result;
try
{
var Model = (IComponentModel)Provider.GetService(typeof(SComponentModel));
var Editor = (IEditorOperationsFactoryService)Provider.GetService(typeof(IEditorOperationsFactoryService)); // returns null
var Adaptor = Model.GetService<IVsEditorAdaptersFactoryService>();
IWpfTextView TextView = Adaptor.GetWpfTextView(VsView);
Result = Editor.GetEditorOperations(TextView);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.ToString());
Result = null;
}
return (Result);
}
You can get IEditorOperationsFactoryService instance from variable named Model, like this:
var Model = (IComponentModel)this.ServiceProvider.GetService(typeof(SComponentModel));
var Editor = (IEditorOperationsFactoryService)Model.GetService<IEditorOperationsFactoryService>();
You can get IWpfTextView (that implements ITextView) from IVsTextView using:
IVsTextView textView = ...;
IWpfTextView v = GetEditorAdaptersFactoryService().GetWpfTextView(textView);
private Microsoft.VisualStudio.Editor.IVsEditorAdaptersFactoryService GetEditorAdaptersFactoryService()
{
Microsoft.VisualStudio.ComponentModelHost.IComponentModel componentModel =
(Microsoft.VisualStudio.ComponentModelHost.IComponentModel)serviceProvider.GetService(
typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel));
return componentModel.GetService<Microsoft.VisualStudio.Editor.IVsEditorAdaptersFactoryService>();
}

Visual Studio 2010 error: identifier out of scope when trying to debug

I am stepping through c++ code and I am seeing a bunch of stuff where it says the symbol is undefined.
The strangest one was a method that I put a break point in. I was a couple lines under the method signature and I added a watch to a String^ variable type in the method. The first one I could see the value. The second one in the method signature it said that it was undefined. What could cause this?
If I put the breakpoint on the first line I can see a value in string1, but string2 is undefined. The error message in the watch window is:
error: identifier 'string2' out of scope
Project is in debug mode.
Configuration Properties->C/C++->Optimization->Optimization = Disabled (/Od)
System::String^ MyNameSpace::CodeXML(String^ string1, String^ string2)
{
System::Diagnostics::Stopwatch ^ performance_timer = System::Diagnostics::Stopwatch::StartNew();
if(System::String::IsNullOrEmpty(string1))
return System::String::Empty;
int iTimeLimit=500,flags=0;
bool bDBGFilter=false;
System::String^ abc = System::String::Empty;
if (!System::String::IsNullOrEmpty(string2)) {
System::IO::StringReader^ sr = gcnew System::IO::StringReader(string2);
XPathDocument^ doc;
try {
doc = gcnew XPathDocument(sr);
} catch (System::Xml::XmlException^) {
throw_managed_exception("Bad parameters XML");
}
XPathNavigator^ root = doc->CreateNavigator();
if (XPathNavigator^ nav = root->SelectSingleNode("XXX/A"))
if(!System::String::IsNullOrEmpty(nav->Value))
iTimeLimit = nav->ValueAsInt;
if (XPathNavigator^ nav = root->SelectSingleNode("XXX/B"))
if(!System::String::IsNullOrEmpty(nav->Value))
flags = nav->ValueAsInt;
if (XPathNavigator^ nav = root->SelectSingleNode("XXX/C"))
if(!System::String::IsNullOrEmpty(nav->Value))
abc = nav->Value->Trim();
}
MyReport Report(EMPTY_STRING, iTimeLimit);
ExtractedData^ ed = gcnew ExtractedData();
if(System::String::IsNullOrEmpty(abc))
Report.SetHasSuperfilter(false);
else
Report.SetHasSuperfilter(true);
Report.init();
bool bRet = ExtractCodes(string1, abc, ed, Report);
if (!bRet)
throw_managed_exception("ExtractCodes returned false");
ostringstream dgn_strm;
Report.summarize(dgn_strm);
performance_timer->Stop();
Report.add_performance_output("CodeXML", (long)performance_timer->ElapsedMilliseconds);
String^ rv = OutputWriter::serialize(ed, Report);
if (DBO d = "old") d << dgn_strm.str();
MappingDiagnosticsSummaryLogger::IncDocCount();
MappingDiagnosticsSummaryLogger::Log();
return rv;
}
I stepped up a level in the call stack and I can see the value of the variable by holding my mouse over it. I just cannot see it in the function with the break point is.
virtual System::String^ ParentFunction(System::String^ string1, System::String^ string2) {
return myObject->CodeXML(string1, string2);
}

Nothing happens with my event listener on click in javascript

I have these functions :
createTreeItem: function (num, val)
{
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var i = document.createElementNS(XUL_NS, "treeitem");
var r = document.createElementNS(XUL_NS, "treerow");
var c1 = document.createElementNS(XUL_NS, 'treecell');
var c2 = document.createElementNS(XUL_NS, 'treecell');
var c3 = document.createElementNS(XUL_NS, 'treecell');
i.setAttribute("container", true);
i.setAttribute("open", true);
c1.setAttribute("label", num);
c2.setAttribute("label", val);
c3.setAttribute("value", false);
r.appendChild(c1);
r.appendChild(c2);
r.appendChild(c3);
i.appendChild(r);
i.addEventListener("click", test, false);
return i;
}
test: function ()
{
alert("zero");
}
func: function (liste)
{
try
{
root = document.getElementById("treeRoot");
var current;
for(o in liste)
{
current = createTreeItem(liste[o].id, liste[o].nom_scenario);
root.appendChild(current);
}
}
catch(e)
{
alert(e);
}
}
I am creating elements in a tree and I would like to add event listeners on each element created. The problem is that nothing happens.
In the code, Liste is the response of a json request. It contains all the elements I want to create in my xul file.
I'm not super familiar with this syntax, but my bet is that the test function isn't being 'hoisted' because of how it's being defined. try moving the 'test' function above the 'createTreeItem' function or just defining test like so:
function test() {
...
}
That way when it gets evaluated it will be 'hoisted' to the top so that when you try to add it as the action for the click event, it'll be defined. Not 100% sure this is correct but if I had to bet...

Cannot update label on Google Apps Script GUI Builder Interface at runtime

I have an interface that calls a script for spreadsheet creation using data taken from other spreadsheet. I want the interface to update its labels at runtime in order to give visual feedback to the user and let him know the script is running and it's not stuck. When I try to update the label I put in the interface, it doesn't update the first time, but updates correctly after myFunction() reaches its end. Which means I can see the message "Creation Completed", but the message "Creating file..." is never shown. Also, the button buttonCompile is never disabled so it seems that the instructions before myFunction() are not executed at all. How can I get the labels updated and the button disabled before myFunction() starts executing? (I already double-checked variable references)
function doGet() {
var app = UiApp.createApplication();
app.add(app.loadComponent("File creation"));
var buttonCreate = app.getElementById('createBtn');
var handlerCrea = app.createServerHandler('createClickHandler');
buttonCreate.addClickHandler(handlerCreate);
return app;
}
function createClickHandler(e) {
var app = UiApp.getActiveApplication();
var label = app.getElementById('createLbl');
label.setText("Creating file...");
var buttonCompile = app.getElementById('compileBtn');
buttonCompile.setEnabled(false);
myFunction();
label.setText("Creation completed.");
buttonCompile.setEnabled(true);
app.close();
return app;
}
The cause of this behavior is that the GUI is updated only after leaving a handler. A workaround is to use two handlers. The 1st one sets the label text to Creating file... and disables the button, the 2nd one executes the myFunction function, changes the text to Creation completed, and eanbles the button. Here is an example. It disables/enables the button and the worker handler simply waits 5 seconds.
function doGet(e) {
var app = UiApp.createApplication();
var container = app.createHorizontalPanel().setId('container');
var btnPerformance = app.createButton("Performance Demo").setId('btnPerformance');
var handlerPerformance = app.createServerHandler('onBtnPerformanceClick');
var handlerWait = app.createServerHandler('onWait');
btnPerformance.addClickHandler(handlerPerformance);
btnPerformance.addClickHandler(handlerWait);
container.add(btnPerformance);
app.add(container);
return app;
}
function enableControls(enable) {
var lstControls = [ 'btnPerformance' ];
var app = UiApp.getActiveApplication();
for (var i = 0; i < lstControls.length; i++) {
var ctl = app.getElementById(lstControls[i]);
ctl.setEnabled(enable);
}
}
function onWait(e) {
enableControls(false);
return UiApp.getActiveApplication();
}
function onBtnPerformanceClick(e) {
Utilities.sleep(5000);
enableControls(true);
return UiApp.getActiveApplication();
}

Resources