Example #1
0
        public void SimpleCompletion()
        {
            var app = IntegrationTestHelper.CreateApp(Output);

            // Position (12,2) is right after 'x.'
            var item = app.GetDocumentItemFromContent(
                @"interface I { a : string};
const x : I = undefined;
const y = x.");

            var completionItems = app
                                  .NotifyDocumentOpened(item)
                                  .Invoke(
                "textDocument/completion",
                new TextDocumentPositionParams
            {
                Position = new Position {
                    Character = 12, Line = 2
                },
                TextDocument = new TextDocumentIdentifier {
                    Uri = item.Uri
                }
            })
                                  .GetLastInvocationResult <List <CompletionItem> >();

            // One single completion item is expected, with insert text 'a'
            Assert.Equal(1, completionItems.Count);
            Assert.Equal("a", completionItems.First().InsertText);
        }
Example #2
0
        public void WorkspaceLoadingCompletes()
        {
            var messages = IntegrationTestHelper
                           .CreateApp(Output, forceSynchronousMessages: true)
                           .Invoke("exit")
                           .WorkspaceLoadingMessages;

            Assert.True(messages.Any(message => message.Status == WorkspaceLoadingState.Success));
        }
Example #3
0
        public void DiagnosticsAreProvidedOnMalformedSpec()
        {
            var lastDiagnostic = IntegrationTestHelper
                                 .CreateApp(Output)
                                 .NotifyDocumentOpened(
                @"const x = 42; 
const y = ")
                                 .PublishDiagnostics
                                 .Last();

            // Two diagnostics are expected, the expression after the '=' is missing and the final semicolon as well
            Assert.Contains(lastDiagnostic.Diagnostics, diag => diag.Message == Errors.Semicolon_expected.Message);
            Assert.Contains(lastDiagnostic.Diagnostics, diag => diag.Message == Errors.Expression_expected.Message);
        }
Example #4
0
        private IntegrationTestHelper SetupForProjectManagementTests()
        {
            var app = IntegrationTestHelper.CreateApp(Output);

            var sourceFileConfigurations = new List <AddSourceFileConfiguration>
            {
                new AddSourceFileConfiguration
                {
                    FunctionName           = "build",
                    PropertyName           = "sources",
                    ArgumentTypeName       = "Arguments",
                    ArgumentPosition       = 0,
                    ArgumentTypeModuleName = "__Config__"
                }
            };

            var addSourceConfiguration = new AddSourceFileConfigurationParams
            {
                Configurations = sourceFileConfigurations.ToArray()
            };

            app.SendNotification("dscript/sourceFileConfiguration", addSourceConfiguration);

            app.NotifyDocumentOpened(
                @"
namespace StaticLibrary {
     export interface Arguments {
         sources: File[];
     }

     export interface BuildResult {        
     }

     export function build(args: Arguments): BuildResult {
        return undefined;
     }
}");

            return(app);
        }
Example #5
0
        public void CompletionOnInterfaceMerging()
        {
            var app = IntegrationTestHelper.CreateApp(Output);

            // Position (12,2) is right after 'x.'
            var item = app.GetDocumentItemFromContent(
                @"export interface I { a : string};
const x : I = undefined;
const y = x.");

            var completionRequest = new TextDocumentPositionParams
            {
                Position = new Position {
                    Character = 12, Line = 2
                },
                TextDocument = new TextDocumentIdentifier {
                    Uri = item.Uri
                }
            };

            // We call completion once. Then add another file that extends the interface and call completion again
            app
            .NotifyDocumentOpened(item)
            .Invoke <TextDocumentPositionParams, List <CompletionItem> >(
                "textDocument/completion", completionRequest, out var completionList1)
            .NotifyDocumentOpened(@"export interface I { b: string }")
            .Invoke <TextDocumentPositionParams, List <CompletionItem> >(
                "textDocument/completion", completionRequest, out var completionList2)
            .Shutdown();

            // One single completion item is expected first, with insert text 'a'
            Assert.Equal(1, completionList1.Count);
            Assert.Equal("a", completionList1.First().InsertText);

            // Two completion items are expected after extending the interface, with insert text 'a' and 'b'
            Assert.Equal(2, completionList2.Count);
            Assert.Contains(completionList2, completionItem => completionItem.InsertText == "a");
            Assert.Contains(completionList2, completionItem => completionItem.InsertText == "b");
        }
Example #6
0
        public void ReferenceTheNewExposedVariableFromTheOldDocumentShouldWork()
        {
            var spec1 = IntegrationTestHelper.CreateDocument(
                "spec1.dsc", "export const x = 42;");

            var spec2 = IntegrationTestHelper.CreateDocument(
                "spec2.dsc", "export const y = 42;");

            // Create an app with only the first spec.
            var app = IntegrationTestHelper.CreateApp(Output, spec1);

            var diagnostics = app
                              // Open the second spec
                              .NotifyDocumentOpened(spec2)
                              // Then changing the first spec to use the value from the second spec.
                              .NotifyDocumentOpened(
                IntegrationTestHelper.CreateDocument(
                    "spec1.dsc", "export const x = y;"))
                              .PublishDiagnostics;

            Assert.Empty(diagnostics.Where(d => d.Diagnostics.Length != 0));
        }