Search in sources :

Example 1 with BSLTokenizer

use of com.github._1c_syntax.bsl.parser.BSLTokenizer in project bsl-language-server by 1c-syntax.

the class DocumentContext method rebuild.

public void rebuild(String content, int version) {
    computeLock.lock();
    boolean versionMatches = version == this.version && version != 0;
    boolean contentWasCleared = this.content == null;
    if (versionMatches && !contentWasCleared) {
        clearDependantData();
        computeLock.unlock();
        return;
    }
    clearSecondaryData();
    symbolTree.clear();
    this.content = content;
    tokenizer = new BSLTokenizer(content);
    this.version = version;
    computeLock.unlock();
}
Also used : BSLTokenizer(com.github._1c_syntax.bsl.parser.BSLTokenizer)

Example 2 with BSLTokenizer

use of com.github._1c_syntax.bsl.parser.BSLTokenizer in project bsl-language-server by 1c-syntax.

the class CommentedCodeDiagnostic method isTextParsedAsCode.

private boolean isTextParsedAsCode(String text) {
    if (!codeRecognizer.meetsCondition(text)) {
        return false;
    }
    BSLTokenizer tokenizer = new BSLTokenizer(uncomment(text));
    final List<Token> tokens = tokenizer.getTokens();
    // Если меньше двух токенов нет смысла анализировать - это код
    if (tokens.size() >= MINIMAL_TOKEN_COUNT) {
        List<Integer> tokenTypes = tokens.stream().map(Token::getType).filter(t -> t != BSLParser.WHITE_SPACE).collect(Collectors.toList());
        // Если два идентификатора идут подряд - это не код
        for (int i = 0; i < tokenTypes.size() - 1; i++) {
            if (tokenTypes.get(i) == BSLParser.IDENTIFIER && tokenTypes.get(i + 1) == BSLParser.IDENTIFIER) {
                return false;
            }
        }
    }
    return true;
}
Also used : CodeAction(org.eclipse.lsp4j.CodeAction) CodeActionProvider(com.github._1c_syntax.bsl.languageserver.providers.CodeActionProvider) CodeRecognizer(com.github._1c_syntax.bsl.languageserver.recognizer.CodeRecognizer) Token(org.antlr.v4.runtime.Token) BSLFootprint(com.github._1c_syntax.bsl.languageserver.recognizer.BSLFootprint) BSLParser(com.github._1c_syntax.bsl.parser.BSLParser) Diagnostic(org.eclipse.lsp4j.Diagnostic) DiagnosticType(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) DiagnosticTag(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DiagnosticSeverity(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) List(java.util.List) DiagnosticMetadata(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata) TextEdit(org.eclipse.lsp4j.TextEdit) MethodDescription(com.github._1c_syntax.bsl.languageserver.context.symbol.description.MethodDescription) Map(java.util.Map) Optional(java.util.Optional) BSLTokenizer(com.github._1c_syntax.bsl.parser.BSLTokenizer) MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) DiagnosticParameter(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticParameter) BSLTokenizer(com.github._1c_syntax.bsl.parser.BSLTokenizer) Token(org.antlr.v4.runtime.Token) BSLFootprint(com.github._1c_syntax.bsl.languageserver.recognizer.BSLFootprint)

Aggregations

BSLTokenizer (com.github._1c_syntax.bsl.parser.BSLTokenizer)2 DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)1 MethodSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol)1 MethodDescription (com.github._1c_syntax.bsl.languageserver.context.symbol.description.MethodDescription)1 DiagnosticMetadata (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata)1 DiagnosticParameter (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticParameter)1 DiagnosticSeverity (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity)1 DiagnosticTag (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag)1 DiagnosticType (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType)1 CodeActionProvider (com.github._1c_syntax.bsl.languageserver.providers.CodeActionProvider)1 BSLFootprint (com.github._1c_syntax.bsl.languageserver.recognizer.BSLFootprint)1 CodeRecognizer (com.github._1c_syntax.bsl.languageserver.recognizer.CodeRecognizer)1 BSLParser (com.github._1c_syntax.bsl.parser.BSLParser)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Token (org.antlr.v4.runtime.Token)1 CodeAction (org.eclipse.lsp4j.CodeAction)1