Scripty icon indicating copy to clipboard operation
Scripty copied to clipboard

No IntelliSense on Scripty objects like Context

Open jnm2 opened this issue 9 years ago • 9 comments

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.

jnm2 avatar Jul 20 '16 12:07 jnm2

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.

daveaglick avatar Jul 20 '16 17:07 daveaglick

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 avatar Aug 21 '16 20:08 redcoreit

@redcoreit Awesome idea! I'm going to add this to the readme - suspect it may help many folks gets up and running.

daveaglick avatar Aug 21 '16 20:08 daveaglick

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

redcoreit avatar Aug 21 '16 21:08 redcoreit

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

Herdo avatar Oct 05 '16 19:10 Herdo

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.

thebigb avatar Oct 19 '16 14:10 thebigb

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

bugproof avatar Jun 21 '18 07:06 bugproof

@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.

daveaglick avatar Jun 21 '18 12:06 daveaglick

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.

TylerBrinkley avatar Jun 21 '18 12:06 TylerBrinkley