<commit_before>##########################################################################
# Copyright (c) Open Law Library. All rights reserved.                   #
# See ThirdPartyNotices.txt in the project root for license information. #
##########################################################################
from pygls import lsp
from pygls.ls import LanguageServer


class MultiRootServer(LanguageServer):

    def text_is_valid(self, text='', max_text_len=10):
        '''
            Checks length of the text. Default is 10.
        '''
        diagnostics = []

        if len(text) > max_text_len:
            diagnostics.append(
                lsp.Diagnostic(
                    lsp.Range(
                        lsp.Position(0, 0),
                        lsp.Range(0, max_text_len)
                    ),
                    f"Max number of characters is {max_text_len}",
                    source=type(ls).__name__
                )
            )

        return diagnostics


ls = MultiRootServer()


@ls.command('custom.Command')
def custom_command(ls, params):
    '''
        Commands are registered with required `name` argument
    '''
    ls.workspace.show_message('Command `custom.Command` executed')


@ls.feature(lsp.TEXT_DOCUMENT_DID_CHANGE)
def doc_did_change(ls, contentChanges=None, textDocument=None, **_kwargs):
    '''
        Validate document
    '''
    # Document is already in our workspace
    doc = ls.workspace.get_document(textDocument['uri'])

    def callback(config):
        max_text_len = config[0].get('maxTextLength', 10)

        diagnostics = ls.text_is_valid(doc.source, max_text_len)

        ls.workspace.publish_diagnostics(
            doc.uri, diagnostics)

    ls.get_configuration({
        'items': [{'scopeUri': doc.uri}]
    }, callback)<commit_msg>Add section to `get_configuration` call.<commit_after>##########################################################################
# Copyright (c) Open Law Library. All rights reserved.                   #
# See ThirdPartyNotices.txt in the project root for license information. #
##########################################################################
from pygls import lsp
from pygls.ls import LanguageServer


class MultiRootServer(LanguageServer):

    def text_is_valid(self, text='', max_text_len=10):
        '''
            Checks length of the text. Default is 10.
        '''
        diagnostics = []

        if len(text) > max_text_len:
            diagnostics.append(
                lsp.Diagnostic(
                    lsp.Range(
                        lsp.Position(0, 0),
                        lsp.Range(0, max_text_len)
                    ),
                    f"Max number of characters is {max_text_len}",
                    source=type(ls).__name__
                )
            )

        return diagnostics


ls = MultiRootServer()


@ls.command('custom.Command')
def custom_command(ls, params):
    '''
        Commands are registered with required `name` argument
    '''
    ls.workspace.show_message('Command `custom.Command` executed')


@ls.feature(lsp.TEXT_DOCUMENT_DID_CHANGE)
def doc_did_change(ls, contentChanges=None, textDocument=None, **_kwargs):
    '''
        Validate document
    '''
    # Document is already in our workspace
    doc = ls.workspace.get_document(textDocument['uri'])

    def callback(config):
        max_text_len = config[0].get('maxTextLength', 10)

        diagnostics = ls.text_is_valid(doc.source, max_text_len)

        ls.workspace.publish_diagnostics(
            doc.uri, diagnostics)

    ls.get_configuration({
        'items': [{'scopeUri': doc.uri, 'section': 'pygls'}]
    }, callback)
{'fraction_non_alphanumeric': 0.17640663223702094, 'fraction_numerical': 0.005436259853220984, 'mean_word_length': 2.4264432029795158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1876349', 'n_tokens_mistral': 1038, 'n_tokens_neox': 962, 'n_words': 221}