use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CallHierarchyProvider method incomingCalls.
public List<CallHierarchyIncomingCall> incomingCalls(DocumentContext documentContext, CallHierarchyIncomingCallsParams params) {
URI uri = documentContext.getUri();
CallHierarchyItem item = params.getItem();
Position position = item.getSelectionRange().getStart();
return referenceResolver.findReference(uri, position).flatMap(Reference::getSourceDefinedSymbol).stream().map(referenceIndex::getReferencesTo).flatMap(Collection::stream).collect(groupingBy(Reference::getFrom, mapping(Reference::getSelectionRange, toCollection(ArrayList::new)))).entrySet().stream().map(entry -> new CallHierarchyIncomingCall(getCallHierarchyItem(entry.getKey()), entry.getValue())).collect(Collectors.toList());
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class TypoDiagnostic method check.
@Override
protected void check() {
String lang = info.getResourceString("diagnosticLanguage");
Map<String, Boolean> checkedWordsForLang = checkedWords.get(lang);
Map<String, List<Token>> tokensMap = getTokensMap(documentContext);
// build string of unchecked words
Set<String> uncheckedWords = tokensMap.keySet().stream().filter(word -> !checkedWordsForLang.containsKey(word)).collect(Collectors.toSet());
if (uncheckedWords.isEmpty()) {
fireDiagnosticOnCheckedWordsWithErrors(tokensMap);
return;
}
// Join with double \n to force LT make paragraph after each word.
// Otherwise results may be flaky cause of sort order of words in file.
String uncheckedWordsString = String.join("\n\n", uncheckedWords);
JLanguageTool languageTool = acquireLanguageTool(lang);
List<RuleMatch> matches = Collections.emptyList();
try {
matches = languageTool.check(uncheckedWordsString, true, JLanguageTool.ParagraphHandling.ONLYNONPARA);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
} finally {
releaseLanguageTool(lang, languageTool);
}
// check words and mark matched as checked
matches.stream().map(ruleMatch -> ruleMatch.getSentence().getTokens()[1].getToken()).forEach(word -> checkedWordsForLang.put(word, true));
// mark unmatched words without errors as checked
uncheckedWords.forEach(word -> checkedWordsForLang.putIfAbsent(word, false));
fireDiagnosticOnCheckedWordsWithErrors(tokensMap);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class InvalidCharacterInFileDiagnostic method getQuickFixes.
@Override
public List<CodeAction> getQuickFixes(List<Diagnostic> diagnostics, CodeActionParams params, DocumentContext documentContext) {
List<TextEdit> textEdits = new ArrayList<>();
diagnostics.stream().filter(diagnostic -> diagnostic.getMessage().equals(diagnosticMessageSpace)).forEach((Diagnostic diagnostic) -> {
Range range = diagnostic.getRange();
TextEdit textEdit = new TextEdit(range, ILLEGAL_SPACE_PATTERN.matcher(documentContext.getText(range)).replaceAll(" "));
textEdits.add(textEdit);
});
diagnostics.stream().filter(diagnostic -> diagnostic.getMessage().equals(diagnosticMessageDash)).forEach((Diagnostic diagnostic) -> {
Range range = diagnostic.getRange();
TextEdit textEdit = new TextEdit(range, ILLEGAL_PATTERN.matcher(documentContext.getText(range)).replaceAll("-"));
textEdits.add(textEdit);
});
return CodeActionProvider.createCodeActions(textEdits, info.getResourceString("quickFixMessage"), documentContext.getUri(), diagnostics);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class MethodSymbolMarkupContentBuilderTest method testContentFromDirectFile.
@Test
void testContentFromDirectFile() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
var methodSymbol = documentContext.getSymbolTree().getMethodSymbol("ИмяФункции").orElseThrow();
// when
var content = markupContentBuilder.getContent(methodSymbol).getValue();
assertThat(content).isNotEmpty();
var blocks = Arrays.asList(content.split("---\n?"));
assertThat(blocks).hasSize(5);
assertThat(blocks.get(0)).isEqualTo("```bsl\n" + "Функция ИмяФункции(Знач П1: Дата | Число, П2: Число = -10, П2_5, Знач П3: Структура = \"\", " + "П4: Массив | СписокЗначений, ПДата: См. ОбщийМодуль.СуперМетод() = '20100101', ПДатаВремя = '20110101121212', " + "П6 = Ложь, П7 = Истина, П8 = Неопределено, П9 = NULL) Экспорт: Строка | Структура\n```\n\n");
assertThat(blocks.get(1)).matches("Метод из file://.*/src/test/resources/hover/methodSymbolMarkupContentBuilder.bsl\n\n");
assertThat(blocks.get(2)).isEqualTo("Описание функции.\nМногострочное.\n\n");
assertThat(blocks.get(3)).isEqualTo("**Параметры:**\n\n" + "* **П1**: `Дата` | `Число` - Описание даты/числа \n" + "* **П2**: `Число` - Описание числа \n" + "* **П2_5**: \n" + "* **П3**: `Структура` - Описание строки<br> продолжается на следующей строкке: \n" + " * **Поле1**: `Число` - Описание поле1 \n" + " * **Поле2**: `Строка` - Описание поле2 \n" + " * **Поле3**: `Структура` : \n" + " * **Поле31**: `строка` \n" + " * **Поле32**: `Структура` : \n" + " * **Поле321**: `Число` - Описание поля 321 \n" + " * **Поле33**: `строка` \n" + " * **Поле4**: `строка` \n" + "* **П4**: \n" + " `Массив` - Описание Массива \n" + " `СписокЗначений` - Описание списка \n" + "* **ПДата**: [См. ОбщийМодуль.СуперМетод()](ОбщийМодуль.СуперМетод()) \n" + "* **ПДатаВремя**: \n" + "* **П6**: \n" + "* **П7**: \n" + "* **П8**: \n" + "* **П9**: \n" + "\n");
assertThat(blocks.get(4)).isEqualTo("**Возвращаемое значение:**\n\n" + " `Строка` - вернувшаяся строка \n" + " `Структура` - Описание строки<br> продолжается на следующей строкке: \n" + " * **Поле1**: `Число` - Описание поле1 \n" + " * **Поле2**: `Строка` - Описание поле2 \n" + " * **Поле3**: `Структура` : \n" + " * **Поле31**: `строка` \n" + " * **Поле32**: `Структура`\n\n");
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class VariableSymbolMarkupContentBuilderTest method testMethodVarContentFromDirectFile_2_comments_strings.
@Test
void testMethodVarContentFromDirectFile_2_comments_strings() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
final var symbolTree = documentContext.getSymbolTree();
var methodSymbol = symbolTree.getMethodSymbol("ИмяФункции").orElseThrow();
var varSymbol = symbolTree.getVariableSymbol("Имя_ОписаниеСверхуДвеСтроки_Функция", methodSymbol).orElseThrow();
// when
var content = markupContentBuilder.getContent(varSymbol).getValue();
assertThat(content).isNotEmpty();
var blocks = Arrays.asList(content.split("---\n?"));
assertThat(blocks).hasSize(3);
assertThat(blocks.get(0)).isEqualTo("```bsl\n" + "Перем Имя_ОписаниеСверхуДвеСтроки_Функция\n" + "```\n" + "\n");
assertThat(blocks.get(1)).matches("Переменная из file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl.ИмяФункции\n" + "\n");
// TODO баг - нет \n для многострочного описания переменной
assertThat(blocks.get(2)).matches("описание 1 строка\n2 строка\n" + "\n");
}
Aggregations