<commit_before>import os
import subprocess

try:
    from typing import Any, List, Dict, Tuple, Callable, Optional
    assert Any and List and Dict and Tuple and Callable and Optional
except ImportError:
    pass

import sublime_plugin
import sublime

from .url import filename_to_uri
from .protocol import (
    Request, Notification
)
from .settings import (
    ClientConfig, settings, load_settings, unload_settings
)
from .logging import debug, exception_log, server_log
from .rpc import Client
from .workspace import get_project_path
from .configurations import (
    config_for_scope, is_supported_view
)
from .clients import (
    add_window_client, window_clients, unload_old_clients,
    unload_window_clients, unload_all_clients
)
from .events import Events
from .documents import (
    initialize_document_sync, notify_did_open
)
from .diagnostics import handle_diagnostics, remove_diagnostics
from .edit import apply_workspace_edit


def startup():
    load_settings()
    Events.subscribe("view.on_load_async", initialize_on_open)
    Events.subscribe("view.on_activated_async", initialize_on_open)
    if settings.show_status_messages:
        sublime.status_message("LSP initialized")
    start_active_view()


def shutdown():
    unload_settings()
    unload_all_clients()


def start_active_view():
    window = sublime.active_window()
    if window:
        view = window.active_view()
        debug('starting initial view', view.file_name())
        if view and is_supported_view(view):
            initialize_on_open(view)
        else:
            debug('view not supported')


TextDocumentSyncKindNone = 0
TextDocumentSyncKindFull = 1
TextDocumentSyncKindIncremental = 2

didopen_after_initialize = list()
unsubscribe_initialize_on_load = None
unsubscribe_initialize_on_activated = None


def initialize_on_open(view: sublime.View):
    window = view.window()

    if not window:
        return

    if window_clients(window):
        unload_old_clients(window)

    global didopen_after_initialize
    config = config_for_scope(view)
    if config:
        if config.enabled:
            if config.name not in window_clients(window):
                didopen_after_initialize.append(view)
                start_window_client(view, window, config)
        else:
            debug(config.name, 'is not enabled')


def handle_initialize_result(result, client, window, config):
    global didopen_after_initialize
    capabilities = result.get("capabilities")
    client.set_capabilities(capabilities)

    # handle server requests and notifications
    client.on_request(
        "workspace/applyEdit",
        lambda params: apply_workspace_edit(sublime.active_window(), params))

    client.on_notification(
        "textDocument/publishDiagnostics",
        lambda params: handle_diagnostics(params))
    client.on_notification(
        "window/showMessage",
        lambda params: sublime.active_window().message_dialog(params.get("message")))
    if settings.log_server:
        client.on_notification(
            "window/logMessage",
            lambda params: server_log(params.get("message")))

    # TODO: These handlers is already filtered by syntax but does not need to
    # be enabled 2x per client
    # Move filtering?
    document_sync = capabilities.get("textDocumentSync")
    if document_sync:
        initialize_document_sync(document_sync)

    Events.subscribe('view.on_close', remove_diagnostics)
<commit_msg>Fix wrong usage of message_dialog().<commit_after>import os
import subprocess

try:
    from typing import Any, List, Dict, Tuple, Callable, Optional
    assert Any and List and Dict and Tuple and Callable and Optional
except ImportError:
    pass

import sublime_plugin
import sublime

from .url import filename_to_uri
from .protocol import (
    Request, Notification
)
from .settings import (
    ClientConfig, settings, load_settings, unload_settings
)
from .logging import debug, exception_log, server_log
from .rpc import Client
from .workspace import get_project_path
from .configurations import (
    config_for_scope, is_supported_view
)
from .clients import (
    add_window_client, window_clients, unload_old_clients,
    unload_window_clients, unload_all_clients
)
from .events import Events
from .documents import (
    initialize_document_sync, notify_did_open
)
from .diagnostics import handle_diagnostics, remove_diagnostics
from .edit import apply_workspace_edit


def startup():
    load_settings()
    Events.subscribe("view.on_load_async", initialize_on_open)
    Events.subscribe("view.on_activated_async", initialize_on_open)
    if settings.show_status_messages:
        sublime.status_message("LSP initialized")
    start_active_view()


def shutdown():
    unload_settings()
    unload_all_clients()


def start_active_view():
    window = sublime.active_window()
    if window:
        view = window.active_view()
        debug('starting initial view', view.file_name())
        if view and is_supported_view(view):
            initialize_on_open(view)
        else:
            debug('view not supported')


TextDocumentSyncKindNone = 0
TextDocumentSyncKindFull = 1
TextDocumentSyncKindIncremental = 2

didopen_after_initialize = list()
unsubscribe_initialize_on_load = None
unsubscribe_initialize_on_activated = None


def initialize_on_open(view: sublime.View):
    window = view.window()

    if not window:
        return

    if window_clients(window):
        unload_old_clients(window)

    global didopen_after_initialize
    config = config_for_scope(view)
    if config:
        if config.enabled:
            if config.name not in window_clients(window):
                didopen_after_initialize.append(view)
                start_window_client(view, window, config)
        else:
            debug(config.name, 'is not enabled')


def handle_initialize_result(result, client, window, config):
    global didopen_after_initialize
    capabilities = result.get("capabilities")
    client.set_capabilities(capabilities)

    # handle server requests and notifications
    client.on_request(
        "workspace/applyEdit",
        lambda params: apply_workspace_edit(sublime.active_window(), params))

    client.on_notification(
        "textDocument/publishDiagnostics",
        lambda params: handle_diagnostics(params))
    client.on_notification(
        "window/showMessage",
        lambda params: sublime.message_dialog(params.get("message")))
    if settings.log_server:
        client.on_notification(
            "window/logMessage",
            lambda params: server_log(params.get("message")))

    # TODO: These handlers is already filtered by syntax but does not need to
    # be enabled 2x per client
    # Move filtering?
    document_sync = capabilities.get("textDocumentSync")
    if document_sync:
        initialize_document_sync(document_sync)

    Events.subscribe('view.on_close', remove_diagnostics)

{'fraction_non_alphanumeric': 0.07348473889772891, 'fraction_numerical': 0.0011572399826414003, 'mean_word_length': 3.7259056732740943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4583341', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1921, 'n_words': 488}