Scripty
Scripty copied to clipboard
No IntelliSense on Scripty objects like Context
I'm not sure if this is a general issue with Roslyn, or whether there is anything the Scripty extension can do about it in the meantime, but it's significant discouragement to getting started.
It's an artifact of how Scripty adds some globals to C# scripts.
When you write a normal .csx file, Roslyn evaluates and executes it in the context of an empty script host. That is, there aren't any globals in the script and you start from a blank slate. Visual Studio has support for providing Intellisense for these scripts by essentially compiling them in the background the same way they would be run by Roslyn which lets the VS editor know what's in scope.
In contrast, Scripty modifies the normal C# script host to add those extra global objects like Context. The Visual Studio editor doesn't know anything about Scripty or that this particular script is going to be evaluated by something other than the default Roslyn script runner. More importantly, it doesn't know about the Scripty objects or that they're in-scope globals, so it doesn't provide Intellisense to them.
Unfortunately this is a tough problem to solve. Scripty could use an alternate file extension, but then we'd be stuck implementing everything having to do with the Visual Studio editing experience instead of riding on top of the default Roslyn script support that's already there. It might be possible to provide "hints" to the editor about additional in-scope globals for certain scripts, but that would involve getting deep into Visual Studio internals and I simply don't have the experience or time to take that on anytime soon.
TL;DR: I recognize this is problem, but there aren't any good/easy solutions at this time.
I'm really new in Scripty world and as a rookie I also have this - intellisenseless - problem!
After I read this I tried to use a workaround:
1, Add template file as .cs 2, Add reference to "Scripty.Core.dll" 3, Write some placeholder code something like this:
using System;
using Scripty.Core;
using Scripty.Core.Output;
using Scripty.Core.ProjectTree;
class Hive
{
public Hive(ScriptContext Context)
{
Context.Output["result"].WriteLine("test");
}
}
4, When you are done comment or remove the placeholder code and rename the .cs file to .csx. 5, Run custom tool
I hope this helps to someone :)
@redcoreit Awesome idea! I'm going to add this to the readme - suspect it may help many folks gets up and running.
I've played a little more with the idea:
1, Add template file as .cs 2, Add reference to "Scripty.Core.dll" 3, Build Action : none 4, Edit, comment first line, save
#define EDIT_MODE
#if EDIT_MODE
using System;
using Scripty.Core;
using Scripty.Core.Output;
using Scripty.Core.ProjectTree;
class Hive
{
public Hive(ScriptContext Context)
{
#endif
Context.Output["result2.txt"].WriteLine("test");
#if EDIT_MODE
}
}
#endif
We might have to add a language service for Visual Studio, which is...
- wrapping the plain "old" C# language service
- includes Scripty specific features
There are two versions, a "legacy language service", and the new solution using MEF: https://msdn.microsoft.com/en-us/library/dd885118.aspx
I ended up with the following construction based on your idea @redcoreit:
Test.csx.cs
#if !TRACE
// Assembly references here
#r ".\bin\Debug\Something.dll"
#endif
// Usings here
using Scripty.Core;
using Something;
#if TRACE
namespace ScriptContainer
{
class ScriptContainer
{
public ScriptContainer(ScriptContext Context)
{
#endif
// Script here
#if TRACE
}
}
}
#endif
Test.csx
#load "Test.csx.cs"
This assumes that TRACE is enabled for your Debug and Release configurations.
Now you don't have to switch between file extensions.
Any solution for this? I started to use razor templates to generate source code because at least there I have some IntelliSense using @inherits
Using scripty I couldn't get IntelliSense to work
@lecoque Other than the suggestions above, there's no current plans to enhance Intellisense support. While I'm still planning a new major release of Scripty later this summer, I don't expect this position will change. Because Scripty uses .csx files, we're kind of limited by the Intellisense support built into VS and VS Code for Roslyn scripting. Extending beyond that would be a pretty major effort in and of itself.
Could we use a static using statement to achieve making those properties available with intellisense? Though I suppose we'd still need to #r the .dll.