Search in sources :

Example 31 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class UsingModalWindowsDiagnosticTest method testUse.

@Test
void testUse() {
    DocumentContext documentContext = getDocumentContextWithUseFlag(UseMode.USE);
    List<Diagnostic> diagnostics = getDiagnostics(documentContext);
    assertThat(diagnostics).isEmpty();
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test)

Example 32 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class DisableDiagnosticTriggeringSupplierTest method testGetCodeActions.

@Test
void testGetCodeActions() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/suppliers/disableDiagnosticTriggering.bsl");
    TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
    CodeActionContext codeActionContext = new CodeActionContext();
    codeActionContext.setDiagnostics(documentContext.getDiagnostics());
    CodeActionParams params = new CodeActionParams();
    params.setRange(new Range());
    params.setTextDocument(textDocumentIdentifier);
    params.setContext(codeActionContext);
    List<CodeAction> codeActions = codeActionSupplier.getCodeActions(params, documentContext);
    assertThat(codeActions).hasSize(10).anyMatch(codeAction -> codeAction.getTitle().equals("Disable all diagnostic in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable NumberOfValuesInStructureConstructor in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable ExportVariables in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable IfElseDuplicatedCondition in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable CanonicalSpellingKeywords in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable FunctionShouldHaveReturn in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable IfElseIfEndsWithElse in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MagicNumber in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MissingSpace in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MissingVariablesDescription in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable all diagnostic in file"));
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) CodeAction(org.eclipse.lsp4j.CodeAction) DirtiesContext(org.springframework.test.annotation.DirtiesContext) Language(com.github._1c_syntax.bsl.languageserver.configuration.Language) Assertions.assertThat(com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) List(java.util.List) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) Ranges(com.github._1c_syntax.bsl.languageserver.utils.Ranges) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) PostConstruct(javax.annotation.PostConstruct) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) CodeAction(org.eclipse.lsp4j.CodeAction) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Range(org.eclipse.lsp4j.Range) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class DisableDiagnosticTriggeringSupplierTest method testGetCodeActionsRegion.

@Test
void testGetCodeActionsRegion() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/suppliers/disableDiagnosticTriggering.bsl");
    TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
    Range range = Ranges.create(53, 0, 56, 38);
    CodeActionContext codeActionContext = new CodeActionContext();
    codeActionContext.setDiagnostics(documentContext.getDiagnostics().stream().filter(diagnostic -> Ranges.containsRange(range, diagnostic.getRange())).collect(Collectors.toList()));
    CodeActionParams params = new CodeActionParams();
    params.setRange(range);
    params.setTextDocument(textDocumentIdentifier);
    params.setContext(codeActionContext);
    List<CodeAction> codeActions = codeActionSupplier.getCodeActions(params, documentContext);
    assertThat(codeActions).hasSize(8).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MagicNumber in range")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MissingSpace in range")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MagicNumber in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MissingSpace in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable all diagnostic in range")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable all diagnostic in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable CanonicalSpellingKeywords in range")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable CanonicalSpellingKeywords in file"));
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) CodeAction(org.eclipse.lsp4j.CodeAction) DirtiesContext(org.springframework.test.annotation.DirtiesContext) Language(com.github._1c_syntax.bsl.languageserver.configuration.Language) Assertions.assertThat(com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) List(java.util.List) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) Ranges(com.github._1c_syntax.bsl.languageserver.utils.Ranges) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) PostConstruct(javax.annotation.PostConstruct) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) CodeAction(org.eclipse.lsp4j.CodeAction) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Range(org.eclipse.lsp4j.Range) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class DisableDiagnosticTriggeringSupplierTest method testGetCodeActionsOneLine.

@Test
void testGetCodeActionsOneLine() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/suppliers/disableDiagnosticTriggering.bsl");
    TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
    Range range = Ranges.create(53, 0, 53, 30);
    CodeActionContext codeActionContext = new CodeActionContext();
    codeActionContext.setDiagnostics(documentContext.getDiagnostics().stream().filter(diagnostic -> Ranges.containsRange(range, diagnostic.getRange())).collect(Collectors.toList()));
    CodeActionParams params = new CodeActionParams();
    params.setRange(range);
    params.setTextDocument(textDocumentIdentifier);
    params.setContext(codeActionContext);
    List<CodeAction> codeActions = codeActionSupplier.getCodeActions(params, documentContext);
    assertThat(codeActions).hasSize(6).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MagicNumber in line")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MissingSpace in line")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MagicNumber in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable MissingSpace in file")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable all diagnostic in line")).anyMatch(codeAction -> codeAction.getTitle().equals("Disable all diagnostic in file"));
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) CodeAction(org.eclipse.lsp4j.CodeAction) DirtiesContext(org.springframework.test.annotation.DirtiesContext) Language(com.github._1c_syntax.bsl.languageserver.configuration.Language) Assertions.assertThat(com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) List(java.util.List) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) Ranges(com.github._1c_syntax.bsl.languageserver.utils.Ranges) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) PostConstruct(javax.annotation.PostConstruct) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) CodeAction(org.eclipse.lsp4j.CodeAction) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Range(org.eclipse.lsp4j.Range) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 35 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.

the class GenerateStandardRegionsSupplierTest method testGetCodeActions.

@Test
void testGetCodeActions() {
    // given
    String filePath = "./src/test/resources/suppliers/generateRegion.bsl";
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(filePath);
    List<Diagnostic> diagnostics = new ArrayList<>();
    TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
    CodeActionContext codeActionContext = new CodeActionContext();
    codeActionContext.setDiagnostics(diagnostics);
    CodeActionParams params = new CodeActionParams();
    params.setRange(new Range());
    params.setTextDocument(textDocumentIdentifier);
    params.setContext(codeActionContext);
    // when
    List<CodeAction> codeActions = codeActionSupplier.getCodeActions(params, documentContext);
    assertThat(codeActions).hasSize(1).anyMatch(codeAction -> codeAction.getTitle().equals("Generate missing regions"));
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) CodeAction(org.eclipse.lsp4j.CodeAction) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Range(org.eclipse.lsp4j.Range) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)86 Test (org.junit.jupiter.api.Test)69 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)57 Diagnostic (org.eclipse.lsp4j.Diagnostic)36 List (java.util.List)22 Position (org.eclipse.lsp4j.Position)21 SneakyThrows (lombok.SneakyThrows)17 Path (java.nio.file.Path)16 CodeAction (org.eclipse.lsp4j.CodeAction)16 TestUtils (com.github._1c_syntax.bsl.languageserver.util.TestUtils)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 Collectors (java.util.stream.Collectors)14 Range (org.eclipse.lsp4j.Range)13 ArrayList (java.util.ArrayList)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)12 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)12 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)11 MethodSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol)10 MDCommonModule (com.github._1c_syntax.mdclasses.mdo.MDCommonModule)10