Giter VIP home page Giter VIP logo

npl's Introduction

NPL

Build Status

NPL/Lua Language Service and debugger (attach to process)

This is NPL/Lua extension for visual studio 2010/2012/2013/2015/2017

๐Ÿ‘‰ See also the new NPL/Lua extension for visual studio 2022 or above.

Install here or directly from visual studio: http://visualstudiogallery.msdn.microsoft.com/7782dc20-924a-4726-8656-d876cdbb3417

Install

Please note, there are extra install steps to complete the installation(either clean or upgrade should apply).

  • Please also install latest visual studio redist dll, if you are installing to early versions of vs.
  • install normally to visual studio
  • run visual studio as Administrators, Select menu: Tools->Launch NPL debugger
  • Click register button to complete installation
  • restart visual studio (no administrators required), Tools->Launch NPL debugger, click Attach to debug any running process
  • optional: disable the plugin, restart vs and then enable it again (i.e. refresh DEBUG engine dll cache).

Note1: if you can not attach

  • make sure to click register button as administrators, and restarted vs.
  • Disable the plugin, restart vs and then enable and restart vs again after registered the dll.(this will force visual studio to reload cached debug engine configurations)
  • you are actually attaching to an ParaEngine/NPL process with commandline: debug="main". (Download app from https://github.com/LiXizhi/ParaCraftSDK)
  • Make sure you have installed latest visual studio redist dll, if you are installing to early versions of vs.
  • you need to wait until the cursor turns to normal cusror before click attach button (and click twice)

Code Overview

This is a NPL debug engine based on interprocess communication (IPC). The visusal studio code is based on the offical SampleEngineWorker from microsoft. Basically, - ProjectLauncher(C#) is a visual studio addon that launch a debugged process, - NPLEngine(C#) implement the main interfaces with visual studio shell. - NPLEngineWorker(C++/CLI) implements the low evel debug event system which in turn communicate with the NPL process vis IPC - IPCDebugger.lua (lua/NPL) implements the actual debug hook and debug event.

Syntax highlighting

Support mixed HTML/NPL highlighting.

  • LineScanner.cs: main line based scanner, with cached state for each line. Used for Syntax color and by the parser as well.
    • overwrite two virtual functions SetSource and ScanTokenAndProvideInfoAboutIt to provide text coloring, they are called for each line.
    • for HTML/NPL mixed mode, I have used different bits in the cached state for HTML/NPL and standard lua.
    • Configuration.cs contains all default and custom definitions for syntax coloring.

Matching braces, code sense, goto, etc.

  • all of them is handled by AuthoringScope ParseSource(ParseRequest request) in LanguageService.cs
  • This function is called in the parser thread.
  • more information please see help in visual studio.

Code Snippets Support

Context Menu Implemetation is in LuaCommandFilter. It can also be activated by code-completion by SnippetDeclarationProvider. Vsix package can not install snippet files into desired folder. So all I can do it to instruct the user to do it manually. Right click to bring up the context menu, then click "insert snippets...", a dialog will guide you to register preinstalled code snippets. After that, goto menu::tools::code snippet manager(Ctrl+K+B), and make some modifications, such as removing unused folders to force vs to refresh its code snippet cache, and restart visual studio.

Reformat Code

See NPLFormatHelper.cs and ReformatSpan function in LuaSource.cs

XML documetation

IntelliSense and code completion using XML files under ${SolutionDir}/Documentation. Users can add new XML files for their own application. See ${install path}/Documentation for examples. Filepath can be found in NPL output panel.

Advanced Functions

- AD7StackFrame::ParseText() is rewritten to support expression evaluation. 

Code structure

C#/C++ code is mostly based on the Sample Debug Engine provided by microsoft. I only do the following modification.

  • ProjectLauncher(C#) is modified to launch a process in the normal way.
  • SampleEngineWorker(C++/CLI)'s WorkerAPI.cpp is modified to use IPC to translate event from IPCDebugger.lua, instead of using native C++ debug event.
    • I preserved all native C++ debugging code, and use IsDebuggingNPL() macro to do the switch.
    • DebuggedProcess.h is also modified, see the NPL region.
    • symbol engine is not supported. instead we simply make a map between unsigned int fake address to NPL script filename/line pairs.
    • step into/over/out is supported.
  • ProjectLauncher(C#) is only modified slightly to add Step support(see AD7Engine.cs) and OnStepComplete event(AD7Events.cs)

Basic functions

  • In visual studio, we can launch or attach to a ParaEngine process to debug it.
  • Adding/Removing Breakpoints anytime, anywhere.
  • step into/out of functions, step over lines
  • Mouse over a local or global variable to see its value dumped.
  • Shift+F9 to bring up the expression window, we can type nested NPL table name like "A.B.C", "main_state" or we can exec a string in the current context like "i=1", "log('hello world')", 'i=i+1; return i'. if the expression has a return value, it will be shown in the window.
  • Adding watches is also supported.
  • Currently, we only support debugging one NPL state (usually the main state). To start the debugging, simply call IPCDebugger.StartDebugEngine(); in the NPL state to be debugged. alternatively, we can start it automatically when loading IPCDebugger.lua, provided the command line parameter "debug" is the current NPL state name, such as "main". The queue name can be specified by "debugqueue", which defaults to "NPLDebug"
  • Note: there is no performance penalties when starting a debug engine, it only starts a timer to receive from IPC queue. The IPCdebugger only starts the debug hook whenever visual studio attaches or launched the process. Use Lib:
NPL.load("(gl)script/ide/Debugger/IPCDebugger.lua");
-- start debug engine in the calling NPL state manually.
IPCDebugger.StartDebugEngine();
-- start the debug engine automatically in the "main" state(thread), by loading "IPCDebugger.lua" file and launch with the command line debug="main"
"ParaEngineClient.exe" debug="main" bootstrapper="whateverfile"

debug the debug engine

One need to start the experimental instance of visual studio. "D:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" /RootSuffix Exp

To install pre-requisite packages

  • In NuGet console, run Install-Package VSSDK.Shell.12

Known Issues

  • Run as administrators in order to register C++ dll successfully.
  • Attach process with mixed Native C++/NPL debugging will fail to detach, because the NPL handler thread are paused when the debug engine send the detach message causing the IDE to hang. Avoid using mixed mode debugging, use only NPL debug engine to debug. Select menu Tools->Attach to Process->Select...-->Only check NPL debug engine. Another solution is to use the Project launcher to attach to process. Note: need to press attach twice.
  • Process2.Attach2("NPLDebugEngineV2") will cause the main thread to hang at delayhlp.cpp, which is pretty strange, press the attach button twice will solve the problem. This has something to do with DELAYLOAD of dlls
  • IMPORTANT: One needs to wait a while until cursor is turned to normal cursor before clicking the attach button, otherwise attach will not work. In case of error, try disable and reenable the plugin

How to upgrade to new version of visual studio

  • open NPLEngine.rgs, add new registry entry for new visual studio version.
  • increase the version number in source.extension.vsixmanifest file
  • optional: modify CheckRegisterDebugEngine() in Connect.cs to allow auto registration.
  • modify NPLEngineWorker's include and lib to point to latest visual studio DIA SDK path.

Changes

- TODO: Stack view, please use NPL Code Wiki's HTTP debugger
- TODO: show a hierarchy of table sub objects in expression evaluation result. 

2016.7.13 - fixed function name with underscore - added set breakpoint to NPL http debugger via context menu.

2016.7.1 - support Documentation in each project's folder. - support npl file extension. - support NPL.load F12 to goto file

2016.4.3 - NPL code snippets added: One still needs to manually copy snippets

2016.3.29 - NPL debugger: support stack view

2016.3.28 - NPL language service: added goto definition for opened files and xml configuration files

2016.3.24 - NPL language service: fixed hex number display, added highlighting for functions and self identifier. - NPL language service: quick info added

2016.3.20 - NPL language service: HTML/page mixed mode highlighting added. - NPL language service: fixed idle parsing and outlining support for NPL code. - NPL language service: function navigation window implemented. - NPL language service: parsing errors will be highlighted in code.

2015.12.11 - fixed having to press the Attach button twice by sending the OnLoadComplete event when receiving "Attached" event from NPL process.

2015.11.14 - fixed debug engine dll registration - changed dll name and guid. - added a register button for manual registration in case multiple instances are registered. - fixed dll load error for a wrong version of Microsoft.VisualStudio.Shell.Interop.12.0

2014.2.5 - ported to visual studio 2013

2010.5.15 - Attach process in vs 2010 is supported in addition to launch process. - stepping into/over/out are fully supported. - IPCDebugger.lua's debug_hook function is optimized to run much faster.

npl's People

Contributors

darrengzy avatar lixizhi avatar zhiyuang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

npl's Issues

on `def {}`

i see that indentation in def(){} are the same.
I think the better logic is to ignore content reformat in def{}
what do you think @DarrenGZY

Formatter ignore code in [[]] --[[]] and ""

Case1:

--[[ 
2017-1-1 
]] 
local str = [[
2017-1-1
]]

will be wrongly formatted to

--[[ 
2017 - 1 - 1 
]] 
local str = [[
2017 - 1 - 1
]]

Case2:

def("activate", p1){
    NPL.this(function()
		local +{params(p1)} = msg;
		+{emit()}
	end);
}

will be wrongly formatted to

def("activate", p1){
    NPL.this(function()
    local +{params(p1)} = msg;
    +{emit()}
end);
}

Documentation xml not loaded?

I tryied to modify "Documentation/NplDocumentation.xml" but its changes arent reflected in editor - still showing original content

  • after poking arount in source i found this line so i tryied reload solution / restart whole VS but only thing i got was message on output:
Load 1 NPL doc file(s) in folder: c:\path\to\solution\Documentation

so it seems that xml file is recognized, but not parsed (no error after making xml invalid)

also: is this project still alive in first place? (last commit 13 months old :( )

some info:

  • "project" is actually web site - "File -> Open -> Web Site" (didnt found any lua realated project type)
  • trying to show intel in lua file
  • Visual studios "Help -> About" dump:
Microsoft Visual Studio Community 2017 
Version 15.5.2
VisualStudio.15.Release/15.5.2+27130.2010
Microsoft .NET Framework
Version 4.7.02556

Installed Version: Community

Visual Basic 2017   00369-60000-00001-AA558
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA558
Microsoft Visual C# 2017

Visual C++ 2017   00369-60000-00001-AA558
Microsoft Visual C++ 2017

Visual F# 4.1   00369-60000-00001-AA558
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package   8.10.01106.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.31125.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services   1.0
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017   5.2.51007.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.0.31106.0
Azure App Service Tools v3.0.0

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

GitHub.VisualStudio   2.4.3.1737
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JetBrains ReSharper Ultimate 2017.2.2    Build 109.0.20171006.122324
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright ยฉ 2018 JetBrains, Inc.

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.51120.3

Microsoft Continuous Delivery Tools for Visual Studio   0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

NHibernateModelGenerator Extension   1.0
NHibernateModelGenerator Visual Studio Extension Detailed Info

Node.js Tools   1.4.11025.7
Adds support for developing and debugging Node.js apps in Visual Studio

NPL_LuaLanguageService   1.0
NPL language service for visual studio 2010/2013/2015

NuGet Package Manager   4.5.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

SQL Server Data Tools   15.1.61710.120
Microsoft SQL Server Data Tools

TypeScript Tools   15.5.11025.1
TypeScript Tools for Microsoft Visual Studio

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Unity   3.5.0.2
Visual Studio Tools for Unity

nested {} in def

syntax error and formatter goes wrong when there are nested {} in side def.

def("activate", p1){
	local a = {};
}

highlight inconsistent line ending

line ending is a big issue in crossplatform dev. VS has some default tools, but without visual feedbacks
is it possible for our syntax checker to discover inconsistent line ending and highlight them as if a syntax error (curly ~~~ at end of line)?

BTW, we can use the line ending of the first line as the primary line ending.

Associate new extension

I would like to associate the extension .fh_lua with LiXizhi/NPL. I cannot figure out how to do it in VS 2017. Apparently that should be done in Options | Text Editor | File Extensions, but I don't know which Editor to use. Can you help?

about space before --

The default comment command will generate following comment code

--function FuncExpression:CompileCode(ast)
     --return {ast:tostring()}
--end

which will be formated to

--function FuncExpression:CompileCode(ast)
--return {ast:tostring()}
--end

this makes decomment difficult. how about ignore all spaces before --?

same is true, such as

local a;      -- this is a

code refactor will remove spacing before the code in comment, which is not desired.

code refactor will remove spacing before the code in comment, which is not desired.

--[[
Title: remote procedure call
Author(s): LiXizhi@yeah.net
Date: 2017/2/8
Desc: Create RPC in current NPL thread. Internally it will create a virtual NPL activation file that can be invoked from any thread
use the lib:
------------------------------------------------------------
NPL.load("(gl)script/ide/System/Concurrent/rpc.lua");
local rpc = commonlib.gettable("System.Concurrent.Async.rpc");
rpc:new():init("Test.testRPC", function(self, msg) 
	msg.output=true; 
	return msg; 
end)

Test.testRPC(nil, {"input"}, function(err, msg) 
	assert(msg.output == true and msg[1] == "input")
	echo(msg);
end);
------------------------------------------------------------
]]

becomes

--[[
Title: remote procedure call
Author(s): [email protected]
Date: 2017/2/8
Desc: Create RPC in current NPL thread. Internally it will create a virtual NPL activation file that can be invoked from any thread
use the lib:
------------------------------------------------------------
NPL.load("(gl)script/ide/System/Concurrent/rpc.lua");
local rpc = commonlib.gettable("System.Concurrent.Async.rpc");
rpc:new():init("Test.testRPC", function(self, msg) 
msg.output=true; 
return msg; 
end)

Test.testRPC(nil, {"input"}, function(err, msg) 
assert(msg.output == true and msg[1] == "input")
echo(msg);
end);
------------------------------------------------------------
]]

Block Commenting is not working

When using the "Comment Selection" and Uncomment Selection" command in Visual Studio 2012 (defaults as Ctrl K, Ctrl, C) an error says "This feature is not currently available. It use to work in previous builds.

IPCDebugger.lua

It doesn't compile out of the box as there are references to ParaEngine and some hard coded paths in the solution. It looks awesome though. Is there any chance you could include IPCDebugger.lua so that we can see the whole picture?

Go To Definition:

  1. is it possible to support all the Lua files in the project but not just the opened files?
  2. Go to definition for function/vars , especially vars , is not absolutely correct, it always go to the wrong location

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.