private void TestAutoCompleteLabels(List <AutoCompleteLabelTestInformation> testList) { var autoCompleteProvider = new AutoCompleteProvider(m_fixture.ProviderContext); foreach (var test in testList) { var result = autoCompleteProvider.Completion( new TextDocumentPositionParams() { Position = new Position() { Line = test.line - 1, Character = test.character, }, TextDocument = new TextDocumentIdentifier() { Uri = m_fixture.GetChildUri(test.filePath) } } , CancellationToken.None); Assert.True(result.IsSuccess); var completionItems = result.SuccessValue.Left.OrderBy(ci => ci.Label).ToArray(); Assert.True(test.expectedLabels.Count == completionItems.Length, "Expected label count does not match\r\n" + "Expected: \r \n" + TestItemToString(test) + "Actual: \r\n" + CompletionItemsLabelsToString(completionItems)); foreach (var expectedLabel in test.expectedLabels) { var hasLabel = completionItems.Any(item => item.Label.Equals(expectedLabel)); Assert.True(hasLabel, "Expected labels not found\r\n" + "Expected: \r \n" + TestItemToString(test) + "Actual: \r\n" + CompletionItemsLabelsToString(completionItems)); } } }
public void AutoCompleteWithNestedObjectIteralAssignedToVariable() { var autoCompleteProvider = new AutoCompleteProvider(m_fixture.ProviderContext); var result = autoCompleteProvider.Completion( new TextDocumentPositionParams() { Position = new Position() { Line = 99 - 1, Character = 32, }, TextDocument = new TextDocumentIdentifier() { Uri = m_fixture.GetChildUri(@"module/lib.bxt") } }, CancellationToken.None); Assert.True(result.IsSuccess); var completionItems = result.SuccessValue.Left .OrderBy(ci => ci.Label) .ToArray(); Assert.Equal(1, completionItems.Length); Assert.Equal("interfaceAProperty", completionItems[0].Label); }
public void AutoCompleteFunctionCallThroughReExport() { var autoCompleteProvider = new AutoCompleteProvider(m_fixture.ProviderContext); var result = autoCompleteProvider.Completion( new TextDocumentPositionParams() { Position = new Position() { Line = 3 - 1, Character = 40, }, TextDocument = new TextDocumentIdentifier() { Uri = m_fixture.GetChildUri(@"module\testExportedFunction.bxt") } }, CancellationToken.None); Assert.True(result.IsSuccess); var completionItems = result.SuccessValue.Left .OrderBy(ci => ci.Label) .ToArray(); Assert.Equal(1, completionItems.Length); Assert.Equal("myFunctionProperty", completionItems[0].Label); }
public void AutoCompleteOnImportShouldProvideOnlyOneModule() { var autoCompleteProvider = new AutoCompleteProvider(m_fixture.ProviderContext); var result = autoCompleteProvider.Completion( new TextDocumentPositionParams() { Position = new Position() { Line = 1 - 1, Character = 26, }, TextDocument = new TextDocumentIdentifier() { Uri = m_fixture.GetChildUri(@"project\project.bxt") } }, CancellationToken.None); Assert.True(result.IsSuccess); var completionItems = result.SuccessValue.Left .OrderBy(ci => ci.Label) .ToArray(); Assert.Equal(1, completionItems.Length); // TODO: Change to just BuildXL.DScript check after April 15, 2019 when deployed bits have updated. Assert.True(completionItems[0].Label == "BuildXL.DScript.LanguageServer.UnitTests.Data.Module" || completionItems[0].Label == "BuildXLScript.LanguageServer.UnitTests.Data.Module"); }
public void AutoCompleteWithDot() { var autoCompleteProvider = new AutoCompleteProvider(m_fixture.ProviderContext); var result = autoCompleteProvider.Completion( new TextDocumentPositionParams() { Position = new Position() { Line = 19 - 1, Character = 96, }, TextDocument = new TextDocumentIdentifier() { Uri = m_fixture.GetChildUri(@"project\project.bxt") } }, CancellationToken.None); Assert.True(result.IsSuccess); var completionItems = result.SuccessValue.Left .OrderBy(ci => ci.Label) .ToArray(); Assert.Equal(2, completionItems.Length); Assert.Equal("deploy", completionItems[0].Label); Assert.Equal(CompletionItemKind.Function, completionItems[0].Kind); Assert.Equal( @"Callback for when deployments will be FlattenedResult @param item - The item that is deployable. Think of this as the 'this' pointer which is not accessable from interface implementations. @param targetFolder - The folder to place this deployable item into @param onDuplicate - The error handler for duplicate files @param currentResult - The current flattened result to add the extra flattened files to @return - The updated flattened result.", completionItems[0].Documentation); Assert.Equal("deploy(item: Object, targetFolder: RelativePath, reportDuplicate: ReportDuplicateDeploymentError, currentResult: FlattenedResult, deploymentOptions?: Object)", completionItems[0].Detail); Assert.Equal("name", completionItems[1].Label); Assert.Equal("name", completionItems[1].InsertText); Assert.Equal(CompletionItemKind.Property, completionItems[1].Kind); Assert.Equal(string.Empty, completionItems[1].Documentation); Assert.Equal("name: string", completionItems[1].Detail); }
public void CompletionWithinObjectLiteral() { var autoCompleteProvider = new AutoCompleteProvider(m_fixture.ProviderContext); var result = autoCompleteProvider.Completion( new TextDocumentPositionParams() { Position = new Position() { Line = 24 - 1, Character = 5 - 1, }, TextDocument = new TextDocumentIdentifier() { Uri = m_fixture.GetChildUri(@"project\project.bxt") } }, CancellationToken.None); Assert.True(result.IsSuccess); var completionItems = result.SuccessValue.Left .OrderBy(ci => ci.Label) .ToArray(); Assert.Equal(2, completionItems.Length); Assert.Equal("a", completionItems[0].InsertText); Assert.Equal(CompletionItemKind.Property, completionItems[0].Kind); Assert.Equal("doc string for a", completionItems[0].Documentation); Assert.Equal("a?: string", completionItems[0].Detail); Assert.Equal("b", completionItems[1].InsertText); Assert.Equal(CompletionItemKind.Property, completionItems[1].Kind); Assert.Equal("doc string for b", completionItems[1].Documentation); Assert.Equal("b?: DeployableItem", completionItems[1].Detail); }
/// <nodoc /> public Result <ArrayOrObject <CompletionItem, CompletionList>, ResponseError> Completion(TextDocumentPositionParams position, CancellationToken token) { return(m_autoCompleteProvider.Completion(position, token)); }