use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class CommonModuleNameServerCallDiagnosticTest method getDocumentContextFromFile.
@SneakyThrows
void getDocumentContextFromFile() {
Path path = Absolute.path(PATH_TO_METADATA);
Path testFile = Paths.get(PATH_TO_MODULE_FILE).toAbsolutePath();
initServerContext(path);
var configuration = context.getConfiguration();
documentContext = spy(TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context));
module = spy((MDCommonModule) configuration.getModulesByObject().get(documentContext.getUri()));
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class ConsecutiveEmptyLinesDiagnosticTest method checkQuickFixes.
private void checkQuickFixes(String module, boolean haveFix) {
final DocumentContext documentContext = TestUtils.getDocumentContext(module);
List<Diagnostic> diagnostics = getDiagnostics(documentContext);
diagnostics.forEach(diagnostic -> checkFix(documentContext, diagnostic, haveFix));
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class DeprecatedTypeManagedFormDiagnosticTest method testQuickFix.
@Test
void testQuickFix() {
final DocumentContext documentContext = getDocumentContext();
List<Diagnostic> diagnostics = getDiagnostics();
final Diagnostic ruDiagnostic = diagnostics.get(0);
List<CodeAction> quickFixes = getQuickFixes(ruDiagnostic);
assertThat(quickFixes).hasSize(1);
final CodeAction quickFix = quickFixes.get(0);
assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(ruDiagnostic);
assertThat(quickFix).in(documentContext).hasChanges(1).hasNewText("\"ФормаКлиентскогоПриложения\"");
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class AnalyzeCommand method getFileInfoFromFile.
private FileInfo getFileInfoFromFile(Path srcDir, File file) {
String textDocumentContent;
try {
textDocumentContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
DocumentContext documentContext = context.addDocument(file.toURI(), textDocumentContent, 1);
Path filePath = srcDir.relativize(Absolute.path(file));
List<Diagnostic> diagnostics = documentContext.getDiagnostics();
MetricStorage metrics = documentContext.getMetrics();
String mdoRef = "";
Optional<AbstractMDObjectBase> mdObjectBase = documentContext.getMdObject();
if (mdObjectBase.isPresent()) {
mdoRef = mdObjectBase.get().getMdoReference().getMdoRef();
}
FileInfo fileInfo = new FileInfo(filePath, mdoRef, diagnostics, metrics);
// clean up AST after diagnostic computing to free up RAM.
documentContext.clearSecondaryData();
return fileInfo;
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class FormatCommand method formatFile.
@SneakyThrows
private void formatFile(File file) {
String textDocumentContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
final URI uri = file.toURI();
DocumentContext documentContext = serverContext.addDocument(uri, textDocumentContent, 1);
DocumentFormattingParams params = new DocumentFormattingParams();
FormattingOptions options = new FormattingOptions();
options.setInsertSpaces(false);
params.setOptions(options);
final List<TextEdit> formatting = formatProvider.getFormatting(params, documentContext);
serverContext.removeDocument(uri);
if (formatting.isEmpty()) {
return;
}
final TextEdit textEdit = formatting.get(0);
final String newText = textEdit.getNewText();
FileUtils.writeStringToFile(file, newText, StandardCharsets.UTF_8);
}
Aggregations