Пример #1
0
        internal async Task HandleDidOpenTextDocumentNotification(
            DidOpenTextDocumentNotification openParams,
            EventContext eventContext)
        {
            try
            {
                Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification");

                if (IsScmEvent(openParams.TextDocument.Uri))
                {
                    return;
                }

                // read the SQL file contents into the ScriptFile
                ScriptFile openedFile = Workspace.GetFileBuffer(openParams.TextDocument.Uri, openParams.TextDocument.Text);
                if (openedFile == null)
                {
                    return;
                }
                // Propagate the changes to the event handlers
                var textDocOpenTasks = TextDocOpenCallbacks.Select(
                    t => t(openedFile, eventContext));

                await Task.WhenAll(textDocOpenTasks);
            }
            catch (Exception ex)
            {
                Logger.Write(LogLevel.Error, "Unknown error " + ex.ToString());
                // Swallow exceptions here to prevent us from crashing
                // TODO: this probably means the ScriptFile model is in a bad state or out of sync with the actual file; we should recover here
                return;
            }
        }
        public async Task ConnectOnPremTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    testService.WriteToFile(queryTempFile.FilePath, query);

                    DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
                    {
                        TextDocument = new TextDocumentItem
                        {
                            Uri        = queryTempFile.FilePath,
                            LanguageId = "enu",
                            Version    = 1,
                            Text       = query
                        }
                    };

                    await testService.RequestOpenDocumentNotification(openParams);

                    Thread.Sleep(500);
                    var connected = await testService.CalculateRunTime(async() =>
                    {
                        var connectParams = testService.GetConnectionParameters(serverType, Common.PerfTestDatabaseName);
                        return(await testService.Connect(queryTempFile.FilePath, connectParams));
                    }, true);

                    Assert.True(connected, "Connection was not successful");
                }
        }
Пример #3
0
        private async Task VerifyFileIsNotAddedOnDocOpened(string filePath)
        {
            // setup test workspace
            var workspace        = new ServiceLayer.Workspace.Workspace();
            var workspaceService = new WorkspaceService <SqlToolsSettings> {
                Workspace = workspace
            };

            // send a document open event with git:/ prefix URI
            var openParams = new DidOpenTextDocumentNotification
            {
                TextDocument = new TextDocumentItem {
                    Uri = filePath
                }
            };

            await workspaceService.HandleDidOpenTextDocumentNotification(openParams, eventContext : null);

            // verify the file is not being tracked by workspace
            Assert.False(workspaceService.Workspace.ContainsFile(filePath));

            // send a close event with git:/ prefix URI
            var closeParams = new DidCloseTextDocumentParams
            {
                TextDocument = new TextDocumentItem {
                    Uri = filePath
                }
            };

            await workspaceService.HandleDidCloseTextDocumentNotification(closeParams, eventContext : null);

            // this is not that interesting validation since the open is ignored
            // the main validation is that close doesn't raise an exception
            Assert.False(workspaceService.Workspace.ContainsFile(filePath));
        }
Пример #4
0
        internal static async Task <bool> ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri, string databaseName)
        {
            testHelper.WriteToFile(ownerUri, query);

            DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
            {
                TextDocument = new TextDocumentItem
                {
                    Uri        = ownerUri,
                    LanguageId = "enu",
                    Version    = 1,
                    Text       = query
                }
            };

            await testHelper.RequestOpenDocumentNotification(openParams);

            Thread.Sleep(500);
            var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, databaseName);

            bool connected = await testHelper.Connect(ownerUri, connectParams);

            Assert.True(connected, "Connection is successful");
            Console.WriteLine($"Connection to {connectParams.Connection.ServerName} is successful");

            return(connected);
        }
Пример #5
0
        internal async Task HandleDidOpenTextDocumentNotification(
            DidOpenTextDocumentNotification openParams,
            EventContext eventContext)
        {
            Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification");

            // read the SQL file contents into the ScriptFile
            ScriptFile openedFile = Workspace.GetFileBuffer(openParams.TextDocument.Uri, openParams.TextDocument.Text);

            // Propagate the changes to the event handlers
            var textDocOpenTasks = TextDocOpenCallbacks.Select(
                t => t(openedFile, eventContext));

            await Task.WhenAll(textDocOpenTasks);
        }
Пример #6
0
        public async Task CompletionTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestHelper testHelper = new TestHelper())
                {
                    string query = "SELECT * FROM sys.objects";

                    testHelper.WriteToFile(queryTempFile.FilePath, query);

                    DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
                    {
                        TextDocument = new TextDocumentItem
                        {
                            Uri        = queryTempFile.FilePath,
                            LanguageId = "enu",
                            Version    = 1,
                            Text       = query
                        }
                    };

                    await testHelper.RequestOpenDocumentNotification(openParams);

                    Thread.Sleep(500);

                    bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);

                    Assert.True(connected, "Connection is successful");

                    Thread.Sleep(10000);

                    CompletionItem[] completions = await testHelper.RequestCompletion(queryTempFile.FilePath, query, 0, 15);

                    Assert.True(completions != null && completions.Length > 0, "Completion items list is null or empty");

                    Thread.Sleep(50);

                    await testHelper.RequestResolveCompletion(completions[0]);

                    Assert.True(completions != null && completions.Length > 0, "Completion items list is null or empty");

                    await testHelper.Disconnect(queryTempFile.FilePath);
                }
        }
        protected Task HandleDidOpenTextDocumentNotification(
            DidOpenTextDocumentNotification openParams,
            EventContext eventContext)
        {
            ScriptFile openedFile =
                editorSession.Workspace.GetFileBuffer(
                    openParams.Uri,
                    openParams.Text);

            // TODO: Get all recently edited files in the workspace
            this.RunScriptDiagnostics(
                new ScriptFile[] { openedFile },
                editorSession,
                eventContext);

            Logger.Write(LogLevel.Verbose, "Finished opening document.");

            return(Task.FromResult(true));
        }
        public async Task DefinitionTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    string query      = "SELECT * FROM sys.objects";
                    int    lineNumber = 0;
                    int    position   = 23;

                    testService.WriteToFile(queryTempFile.FilePath, query);

                    DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
                    {
                        TextDocument = new TextDocumentItem
                        {
                            Uri        = queryTempFile.FilePath,
                            LanguageId = "enu",
                            Version    = 1,
                            Text       = query
                        }
                    };

                    await testService.RequestOpenDocumentNotification(openParams);

                    Thread.Sleep(500);

                    bool connected = await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath);

                    // Wait for intellisense to be ready
                    var readyParams = await testService.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);

                    Assert.NotNull(readyParams);
                    Assert.True(connected, "Connection is successful");


                    // Request definition for "objects"
                    Location[] locations = await testService.RequestDefinition(queryTempFile.FilePath, query, lineNumber, position);

                    Assert.True(locations != null, "Location is not null and not empty");
                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Пример #9
0
        public async Task WorkspaceContainsFile()
        {
            var workspace        = new ServiceLayer.Workspace.Workspace();
            var workspaceService = new WorkspaceService <SqlToolsSettings> {
                Workspace = workspace
            };
            var openedFile = workspace.GetFileBuffer(TestObjects.ScriptUri, string.Empty);

            // send a document open event
            var openParams = new DidOpenTextDocumentNotification
            {
                TextDocument = new TextDocumentItem {
                    Uri = TestObjects.ScriptUri
                }
            };

            await workspaceService.HandleDidOpenTextDocumentNotification(openParams, eventContext : null);

            // verify the file is being tracked by workspace
            Assert.True(workspaceService.Workspace.ContainsFile(TestObjects.ScriptUri));
        }
Пример #10
0
        public async Task DefinitionTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestHelper testHelper = new TestHelper())
                {
                    string query      = "SELECT * FROM sys.objects";
                    int    lineNumber = 0;
                    int    position   = 23;

                    testHelper.WriteToFile(queryTempFile.FilePath, query);

                    DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
                    {
                        TextDocument = new TextDocumentItem
                        {
                            Uri        = queryTempFile.FilePath,
                            LanguageId = "enu",
                            Version    = 1,
                            Text       = query
                        }
                    };

                    await testHelper.RequestOpenDocumentNotification(openParams);

                    Thread.Sleep(500);

                    bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);

                    Assert.True(connected, "Connection is successful");

                    Thread.Sleep(10000);
                    // Request definition for "objects"
                    Location[] locations = await testHelper.RequestDefinition(queryTempFile.FilePath, query, lineNumber, position);

                    Assert.True(locations != null, "Location is not null and not empty");
                    await testHelper.Disconnect(queryTempFile.FilePath);
                }
        }
Пример #11
0
        public async Task HoverTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestHelper testHelper = new TestHelper())
                {
                    string query = "SELECT * FROM sys.objects";

                    testHelper.WriteToFile(queryTempFile.FilePath, query);

                    DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
                    {
                        TextDocument = new TextDocumentItem
                        {
                            Uri        = queryTempFile.FilePath,
                            LanguageId = "enu",
                            Version    = 1,
                            Text       = query
                        }
                    };

                    await testHelper.RequestOpenDocumentNotification(openParams);

                    Thread.Sleep(500);

                    bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);

                    Assert.True(connected, "Connection was not successful");

                    Thread.Sleep(10000);

                    Hover hover = await testHelper.RequestHover(queryTempFile.FilePath, query, 0, 15);

                    Assert.True(hover != null, "Hover tooltop is null");

                    await testHelper.Disconnect(queryTempFile.FilePath);
                }
        }
 /// <summary>
 /// Request the active SQL script is parsed for errors
 /// </summary>
 public async Task RequestOpenDocumentNotification(DidOpenTextDocumentNotification openParams)
 {
     await Driver.SendEvent(DidOpenTextDocumentNotification.Type, openParams);
 }
Пример #13
0
        public async Task DiagnosticsTests()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestHelper testHelper = new TestHelper())
                {
                    bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);

                    Assert.True(connected, "Connection was not successful");

                    Thread.Sleep(500);

                    string query = "SELECT *** FROM sys.objects";

                    DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
                    {
                        TextDocument = new TextDocumentItem
                        {
                            Uri        = queryTempFile.FilePath,
                            LanguageId = "enu",
                            Version    = 1,
                            Text       = query
                        }
                    };

                    await testHelper.RequestOpenDocumentNotification(openParams);

                    Thread.Sleep(100);

                    var contentChanges = new TextDocumentChangeEvent[1];
                    contentChanges[0] = new TextDocumentChangeEvent
                    {
                        Range = new Range
                        {
                            Start = new Position
                            {
                                Line      = 0,
                                Character = 5
                            },
                            End = new Position
                            {
                                Line      = 0,
                                Character = 6
                            }
                        },
                        RangeLength = 1,
                        Text        = "z"
                    };

                    DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams()
                    {
                        ContentChanges = contentChanges,
                        TextDocument   = new VersionedTextDocumentIdentifier()
                        {
                            Version = 2,
                            Uri     = queryTempFile.FilePath
                        }
                    };

                    await testHelper.RequestChangeTextDocumentNotification(changeParams);

                    Thread.Sleep(100);

                    contentChanges[0] = new TextDocumentChangeEvent
                    {
                        Range = new Range
                        {
                            Start = new Position
                            {
                                Line      = 0,
                                Character = 5
                            },
                            End = new Position
                            {
                                Line      = 0,
                                Character = 6
                            }
                        },
                        RangeLength = 1,
                        Text        = "t"
                    };

                    changeParams = new DidChangeTextDocumentParams
                    {
                        ContentChanges = contentChanges,
                        TextDocument   = new VersionedTextDocumentIdentifier
                        {
                            Version = 3,
                            Uri     = queryTempFile.FilePath
                        }
                    };

                    await testHelper.RequestChangeTextDocumentNotification(changeParams);

                    Thread.Sleep(2500);

                    await testHelper.Disconnect(queryTempFile.FilePath);
                }
        }