public async Task Can_get_signatureHelp_for_workspace_with_buffers() { var container = @"class A { #region nesting #endregion void Operation() { var instance = new C(); } }"; var markup = @"class C { public void Foo() { Foo($$ } }"; var(processed, markLocation) = CodeManipulation.ProcessMarkup(markup); var ws = new Workspace( files: new[] { new File("program.cs", container.EnforceLF()) }, buffers: new[] { new Buffer("program.cs@nesting", processed, markLocation) }); var request = new WorkspaceRequest(ws, activeBufferId: "program.cs@nesting"); var server = GetLanguageService(); var result = await server.GetSignatureHelp(request); result.Signatures.Should().NotBeEmpty(); result.Signatures.First().Label.Should().Be("void C.Foo()"); }
public async Task Get_autocompletion_for_console_methods() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); Console.$$ } } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(generator); var workspace = new Workspace(workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program.EnforceLF()), new Buffer("generators/FibonacciGenerator.cs", processed, position) }); var request = new WorkspaceRequest(workspace, activeBufferId: "generators/FibonacciGenerator.cs"); var server = GetLanguageService(); var result = await server.GetCompletionList(request); result.Items.Should().NotBeNullOrEmpty(); result.Items.Should().NotContain(signature => string.IsNullOrEmpty(signature.Kind)); result.Items.Should().Contain(completion => completion.SortText == "Beep"); var hasDuplicatedEntries = HasDuplicatedCompletionItems(result); hasDuplicatedEntries.Should().BeFalse(); }
public async Task Get_diagnostics() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); adddd Console.WriteLine($$); } } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(generator); var workspace = new Workspace(workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program), new Buffer("generators/FibonacciGenerator.cs", processed, position) }); var request = new WorkspaceRequest(workspace, activeBufferId: "generators/FibonacciGenerator.cs"); var server = await GetLanguageServiceAsync(); var result = await server.GetDiagnostics(request); result.Diagnostics.Should().NotBeNullOrEmpty(); result.Diagnostics.Should().Contain(diagnostics => diagnostics.Message == "generators/FibonacciGenerator.cs(14,17): error CS0246: The type or namespace name \'adddd\' could not be found (are you missing a using directive or an assembly reference?)"); }
public async Task Get_signature_help_for_invalid_location_return_empty() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); Console.WriteLine();$$ } } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(generator); var workspace = new Workspace(workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program), new Buffer("generators/FibonacciGenerator.cs", processed, position) }); var request = new WorkspaceRequest(workspace, activeBufferId: "generators/FibonacciGenerator.cs"); var server = await GetLanguageServiceAsync(); var result = await server.GetSignatureHelp(request); result.Should().NotBeNull(); result.Signatures.Should().BeNullOrEmpty(); }
public async Task Can_show_completions() { var(processed, markLocation) = CodeManipulation.ProcessMarkup("var xa = 3;\n$$a"); var ws = new Workspace(buffers: new[] { new Buffer("default.cs", processed, markLocation) }); var request = new WorkspaceRequest(ws, activeBufferId: "default.cs"); var server = GetLanguageService(); var result = await server.GetCompletionList(request); result.Items.Should().NotBeNullOrEmpty(); result.Items.Should().Contain(i => i.DisplayText == "xa"); }
public async Task Can_show_KeyValuePair_because_it_uses_the_right_reference_assemblies() { var(processed, markLocation) = CodeManipulation.ProcessMarkup("System.Collections.Generic.$$"); var ws = new Workspace(buffers: new[] { new Buffer("default.cs", processed, markLocation) }); var request = new WorkspaceRequest(ws, activeBufferId: "default.cs"); var server = GetLanguageService(); var result = await server.GetCompletionList(request); result.Items.Should().NotBeNullOrEmpty(); result.Items.Should().Contain(i => i.DisplayText == "KeyValuePair"); }
public async Task Get_diagnostics() { var code = @"addd"; var(processed, markLocation) = CodeManipulation.ProcessMarkup(code); var ws = new Workspace(buffers: new[] { new Buffer("", processed, markLocation) }); var request = new WorkspaceRequest(ws, activeBufferId: ""); var server = GetLanguageService(); var result = await server.GetDiagnostics(request); result.Diagnostics.Should().NotBeEmpty(); result.Diagnostics.Should().Contain(diagnostics => diagnostics.Message == "(1,1): error CS0103: The name \'addd\' does not exist in the current context"); }
public async Task Can_show_signatureHelp_for_workspace() { var markup = @"class C { void Foo() { Foo($$ } }"; var(processed, markLocation) = CodeManipulation.ProcessMarkup(markup); var ws = new Workspace(buffers: new[] { new Buffer("program.cs", processed, markLocation) }); var request = new WorkspaceRequest(ws, activeBufferId: "program.cs"); var server = GetLanguageService(); var result = await server.GetSignatureHelp(request); result.Signatures.Should().NotBeEmpty(); result.Signatures.First().Label.Should().Be("void C.Foo()"); }
public async Task Get_autocompletion_can_be_empty() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @" #region codeRegion #endregion ".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup("class $$"); var workspace = new Workspace( workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program), new Buffer("generators/FibonacciGenerator.cs@codeRegion", processed, position) }, files: new[] { new File("generators/FibonacciGenerator.cs", generator) }); var request = new WorkspaceRequest(workspace, activeBufferId: "generators/FibonacciGenerator.cs@codeRegion"); var server = await GetLanguageServiceAsync(); var result = await server.GetCompletionList(request); result.Items.Should().BeEmpty(); }
public async Task Can_show_signature_help_for_extensions() { var code = @"using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { foreach (var i in Fibonacci().Take($$)) { Console.WriteLine(i); } } private static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); } } }"; var(processed, markLocation) = CodeManipulation.ProcessMarkup(code); var ws = new Workspace(buffers: new[] { new Buffer("file.csx", processed, markLocation) }); var request = new WorkspaceRequest(ws, activeBufferId: "file.csx"); var server = await GetLanguageServiceAsync(); var result = await server.GetSignatureHelp(request); result.Signatures.Should().NotBeEmpty(); result.Signatures.First().Label.Should().Be("IEnumerable<TSource> Enumerable.Take<TSource>(IEnumerable<TSource> source, int count)"); result.Signatures.First().Documentation.Value.Should().Be("Returns a specified number of contiguous elements from the start of a sequence."); }
public async Task Get_diagnostics_with_buffer_with_region() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { #region code #endregion } } }".EnforceLF(); var region = @"adddd".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(region); var workspace = new Workspace(workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program), new Buffer(new BufferId("Program.cs", "code"), processed, position) }); var request = new WorkspaceRequest(workspace, activeBufferId: new BufferId("Program.cs", "code")); var server = await GetLanguageServiceAsync(); var result = await server.GetDiagnostics(request); result.Diagnostics.Should().NotBeNullOrEmpty(); result.Diagnostics.Should().Contain(diagnostics => diagnostics.Message == "(1,1): error CS0103: The name 'adddd' does not exist in the current context"); }
public async Task Get_signature_help_for_invalid_location_return_empty() { var code = @"using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { foreach (var i in Fibonacci().Take())$$ { Console.WriteLine(i); } } private static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); } } }"; var(processed, markLocation) = CodeManipulation.ProcessMarkup(code); var ws = new Workspace(buffers: new[] { new Buffer("file.csx", processed, markLocation) }); var request = new WorkspaceRequest(ws, activeBufferId: "file.csx"); var server = await GetLanguageServiceAsync(); var result = await server.GetSignatureHelp(request); result.Should().NotBeNull(); result.Signatures.Should().BeNullOrEmpty(); }
public async Task Get_diagnostics_with_buffer_with_region_in_code_but_not_in_buffer_id() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { #region code error #endregion moreError } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(program); var workspace = new Workspace(workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program), }); var request = new WorkspaceRequest(workspace, activeBufferId: "Program.cs"); var server = await GetLanguageServiceAsync(); var result = await server.GetDiagnostics(request); result.Diagnostics.Should().NotBeNullOrEmpty(); result.Diagnostics.Should().Contain(diagnostics => diagnostics.Message == "Program.cs(13,13): warning CS0168: The variable 'moreError' is declared but never used"); }
public async Task A_script_snippet_workspace_can_be_used_to_get_completions() { await Default.ConsoleWorkspace(); var(processed, position) = CodeManipulation.ProcessMarkup("Console.$$"); using (var agent = new AgentService(StartupOptions.FromCommandLine("hosted"))) { var json = new WorkspaceRequest( requestId: "TestRun", activeBufferId: "default.cs", workspace: Workspace.FromSource( processed, "script", id: "default.cs", position: position)) .ToJson(); var request = new HttpRequestMessage( HttpMethod.Post, @"/workspace/completion") { Content = new StringContent( json, Encoding.UTF8, "application/json") }; var response = await agent.SendAsync(request); var result = await response .EnsureSuccess() .DeserializeAs <CompletionResult>(); result.Items.Should().ContainSingle(item => item.DisplayText == "WriteLine"); } }
public async Task A_console_project_can_be_used_to_get_diagnostics() { await Default.ConsoleWorkspace(); #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { adddd yield return current; next = current + (current = next); Cons$$ } } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(generator); var log = new LogEntryList(); using (LogEvents.Subscribe(log.Add)) using (var agent = new AgentService()) { var json = new WorkspaceRequest(activeBufferId: "generators/FibonacciGenerator.cs", requestId: "TestRun", workspace: Workspace.FromSources( "console", language: "csharp", ("Program.cs", program, 0), ("generators/FibonacciGenerator.cs", processed, position) )).ToJson(); var request = new HttpRequestMessage( HttpMethod.Post, @"/workspace/diagnostics") { Content = new StringContent( json, Encoding.UTF8, "application/json") }; var response = await agent.SendAsync(request); var result = await response .EnsureSuccess() .DeserializeAs <DiagnosticResult>(); result.Diagnostics.Should().NotBeNullOrEmpty(); result.Diagnostics.Should().Contain(diagnostic => diagnostic.Message == "generators/FibonacciGenerator.cs(12,17): error CS0246: The type or namespace name \'adddd\' could not be found (are you missing a using directive or an assembly reference?)"); } }
public async Task A_console_project_can_be_used_to_get_type_completion_with_a_space_in_the_name() { await Default.ConsoleWorkspace(); #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); Cons$$ } } } }".EnforceLF(); #endregion var package = await PackageUtilities.Copy(await Default.ConsoleWorkspace(), "a space"); var(processed, position) = CodeManipulation.ProcessMarkup(generator); var log = new LogEntryList(); using (LogEvents.Subscribe(log.Add)) using (var agent = new AgentService()) { var json = new WorkspaceRequest(activeBufferId: "generators/FibonacciGenerator.cs", requestId: "TestRun", workspace: Workspace.FromSources( package.Name, language: "csharp", ("Program.cs", program, 0), ("generators/FibonacciGenerator.cs", processed, position) )).ToJson(); var request = new HttpRequestMessage( HttpMethod.Post, @"/workspace/completion") { Content = new StringContent( json, Encoding.UTF8, "application/json") }; var response = await agent.SendAsync(request); var result = await response .EnsureSuccess() .DeserializeAs <CompletionResult>(); result.Items.Should().NotBeNullOrEmpty(); result.Items.Should().Contain(completion => completion.SortText == "Console"); } }
public async Task A_console_workspace_can_be_used_to_get_signature_help() { await Default.ConsoleWorkspace(); #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); Console.WriteLine($$); } } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(generator); var log = new LogEntryList(); using (LogEvents.Subscribe(log.Add)) using (var agent = new AgentService()) { var json = new WorkspaceRequest(activeBufferId: "generators/FibonacciGenerator.cs", requestId: "TestRun", workspace: Workspace.FromSources( workspaceType: "console", language: "csharp", ("Program.cs", program, 0), ("generators/FibonacciGenerator.cs", processed, position) )).ToJson(); var request = new HttpRequestMessage( HttpMethod.Post, @"/workspace/signaturehelp") { Content = new StringContent( json, Encoding.UTF8, "application/json") }; var response = await agent.SendAsync(request); var result = await response .EnsureSuccess() .DeserializeAs <SignatureHelpResult>(); result.Signatures.Should().NotBeNullOrEmpty(); result.Signatures.Should().Contain(diagnostic => diagnostic.Label == "void Console.WriteLine(string format, params object[] arg)"); } }
public async Task Get_documentation_with_signature_help_for_console_writeline() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); Console.WriteLine($$); } } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(generator); var package = await PackageUtilities.Copy(await Default.ConsoleWorkspace()); var workspace = new Workspace(workspaceType: package.Name, buffers: new[] { new Buffer("Program.cs", program), new Buffer("generators/FibonacciGenerator.cs", processed, position) }); var request = new WorkspaceRequest(workspace, activeBufferId: "generators/FibonacciGenerator.cs"); var server = await GetLanguageServiceAsync(); var result = await server.GetSignatureHelp(request); result.Signatures.Should().NotBeNullOrEmpty(); var sample = result.Signatures.First(e => e.Label == "void Console.WriteLine(string format, params object[] arg)"); sample.Documentation.Value.Should().Contain("Writes the text representation of the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information."); sample.Parameters.Should().HaveCount(2); sample.Parameters.ElementAt(0).Name.Should().Be("format"); sample.Parameters.ElementAt(0).Label.Should().Be("string format"); sample.Parameters.ElementAt(0).Documentation.Value.Should().Contain("A composite format string."); sample.Parameters.ElementAt(1).Name.Should().Be("arg"); sample.Parameters.ElementAt(1).Label.Should().Be("params object[] arg"); sample.Parameters.ElementAt(1).Documentation.Value.Should().Contain("An array of objects to write using format ."); }
public async Task Get_signature_help_for_jtoken() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); #region codeRegion #endregion } } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup("JToken.FromObject($$);"); var workspace = new Workspace( workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program), new Buffer("generators/FibonacciGenerator.cs@codeRegion", processed, position) }, files: new[] { new File("generators/FibonacciGenerator.cs", generator), }); var request = new WorkspaceRequest(workspace, activeBufferId: "generators/FibonacciGenerator.cs@codeRegion"); var server = await GetLanguageServiceAsync(); var result = await server.GetSignatureHelp(request); result.Signatures.Should().NotBeNullOrEmpty(); result.Signatures.Should().Contain(signature => signature.Label == "JToken JToken.FromObject(object o)"); }
public async Task Get_documentation_with_autocompletion_of_console_methods() { #region bufferSources var program = @"using System; using System.Linq; namespace FibonacciTest { public class Program { public static void Main() { foreach (var i in FibonacciGenerator.Fibonacci().Take(20)) { Console.WriteLine(i); } } } }".EnforceLF(); var generator = @"using System.Collections.Generic; using System; namespace FibonacciTest { public static class FibonacciGenerator { public static IEnumerable<int> Fibonacci() { int current = 1, next = 1; while (true) { yield return current; next = current + (current = next); Console.$$ } } } }".EnforceLF(); #endregion var(processed, position) = CodeManipulation.ProcessMarkup(generator); var workspace = new Workspace(workspaceType: "console", buffers: new[] { new Buffer("Program.cs", program), new Buffer("generators/FibonacciGenerator.cs", processed, position) }); var request = new WorkspaceRequest(workspace, activeBufferId: "generators/FibonacciGenerator.cs"); var server = await GetLanguageServiceAsync(); var result = await server.GetCompletionList(request); result.Should().NotBeNull(); result.Items.Should().NotBeNullOrEmpty(); result.Items .Where(i => i.Documentation != null && !string.IsNullOrWhiteSpace(i.Documentation.Value)) .Select(i => i.Documentation.Value) .Should() .Contain(d => d == "Writes the text representation of the specified Boolean value to the standard output stream."); }