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 = GetLanguageService(); 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 = GetLanguageService(); var result = await server.GetSignatureHelp(request); result.Should().NotBeNull(); result.Signatures.Should().BeNullOrEmpty(); }
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 = GetLanguageService(); var result = await server.GetCompletionList(request); result.Items.Should().BeEmpty(); }
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 = GetLanguageService(); 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_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 = GetLanguageService(); 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 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 = GetLanguageService(); 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 = GetLanguageService(); 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 = GetLanguageService(); 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."); }