Ejemplo n.º 1
0
def _start_diff(buf_id, callback):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		return

	state = _diff_state[buf_id]
	prev_content = state['content']
	content = eutils.content(view)

	@eutils.main_thread
	def _c(result):
		callback(buf_id, result)

		if buf_id in _diff_state:
			state = _diff_state[buf_id]
			state['running'] = False
			if result is not None:
				state['content'] = content

			if state['required']:
				diff(buf_id, callback)
	
	state['required'] = False
	state['running'] = True
	with PyV8.JSLocker():
		threading.Thread(target=_run_diff, args=(prev_content, content, _c)).start()
Ejemplo n.º 2
0
def _start_diff(buf_id):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        return

    state = _diff_state[buf_id]
    prev_content = state['content']
    content = eutils.content(view)
    syntax = get_syntax(view)

    state['required'] = False

    client = ws.find_client({'supports': 'css'})

    if client:
        logger.debug('Use connected "%s" client for diff' % client.name())
        lock_state(state)
        ws.send(
            {
                'action': 'diff',
                'data': {
                    'file': buf_id,
                    'syntax': syntax,
                    'source1': prev_content,
                    'source2': content
                }
            }, client)
    else:
        logger.error('No suitable client for diff')
Ejemplo n.º 3
0
def _start_patch(buf_id, patch):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        logger.debug('No view to patch')
        return

    content = eutils.content(view)
    syntax = get_syntax(view)
    state = _patch_state[buf_id]

    client = ws.find_client({'supports': 'css'})
    logger.debug('Client: %s' % client)

    if client:
        logger.debug('Use connected "%s" client for patching' % client.name())
        lock_state(state)
        ws.send(
            {
                'action': 'patch',
                'data': {
                    'file': buf_id,
                    'syntax': syntax,
                    'patches': patch,
                    'source': content
                }
            }, client)
    else:
        logger.error('No suitable client for patching')
Ejemplo n.º 4
0
def _start_diff(buf_id):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		return

	state = _diff_state[buf_id]
	prev_content = state['content']
	content = eutils.content(view)
	syntax = get_syntax(view)

	state['required'] = False

	client = ws.find_client({'supports': 'css'})

	if client:
		logger.debug('Use connected "%s" client for diff' % client.name())
		lock_state(state)
		ws.send({
			'action': 'diff',
			'data': {
				'file': buf_id,
				'syntax': syntax,
				'source1': prev_content,
				'source2': content
			}
		}, client)
	else:
		logger.error('No suitable client for diff')
Ejemplo n.º 5
0
def _start_patch(buf_id, patch):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		logger.debug('No view to patch')
		return

	content = eutils.content(view)
	syntax = get_syntax(view)
	state = _patch_state[buf_id]


	client = ws.find_client({'supports': 'css'})
	logger.debug('Client: %s' % client)

	if client:
		logger.debug('Use connected "%s" client for patching' % client.name())
		lock_state(state)
		ws.send({
			'action': 'patch',
			'data': {
				'file': buf_id,
				'syntax': syntax,
				'patches': patch,
				'source': content
			}
		}, client)
	else:
		logger.error('No suitable client for patching')
Ejemplo n.º 6
0
def _start_diff(buf_id, callback):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        return

    state = _diff_state[buf_id]
    prev_content = state['content']
    content = eutils.content(view)
    syntax = get_syntax(view)

    @eutils.main_thread
    def _c(result):
        callback(buf_id, result)

        if buf_id in _diff_state:
            state = _diff_state[buf_id]
            state['running'] = False
            if result is not None:
                state['content'] = content

            if state['required']:
                diff(buf_id, callback)

    state['required'] = False
    state['running'] = True

    with PyV8.JSLocker():
        threading.Thread(target=_run_diff,
                         args=(prev_content, content, syntax, _c)).start()
Ejemplo n.º 7
0
def send_patches(buf_id=None, p=None):
    if not buf_id or not p:
        return

    p = eutils.parse_json(p)
    view = eutils.view_for_buffer_id(buf_id)
    if p and view is not None:
        ws.send({"action": "update", "data": {"editorFile": eutils.file_name(view), "patch": p}})
Ejemplo n.º 8
0
def apply_patched_source(buf_id, content):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None or content is None:
		return

	if sublime_ver < 3:
		content = content.decode('utf-8')

	view.run_command('livestyle_replace_content', {'content': content})
Ejemplo n.º 9
0
def apply_patched_source(buf_id, content):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None or content is None:
        return

    if sublime_ver < 3:
        content = content.decode('utf-8')

    view.run_command('livestyle_replace_content', {'content': content})
Ejemplo n.º 10
0
def prepare_diff(buf_id):
	"Prepare buffer for diff'ing"
	if not has_pyv8(): return

	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		return

	if buf_id not in _diff_state:
		_diff_state[buf_id] = {'running': False, 'required': False, 'content': ''}

	_diff_state[buf_id]['content'] = eutils.content(view)
Ejemplo n.º 11
0
def send_patches(buf_id=None, p=None):
    if not buf_id or not p:
        return

    p = parse_json(p)
    view = eutils.view_for_buffer_id(buf_id)
    if p and view is not None:
        send_message({
            'action': 'update',
            'data': {
                'editorFile': eutils.file_name(view),
                'patch': p
            }
        })
Ejemplo n.º 12
0
def send_patches(buf_id=None, p=None):
	if not buf_id or not p:
		return

	p = eutils.parse_json(p)
	view = eutils.view_for_buffer_id(buf_id)
	if p and view is not None:
		ws.send({
			'action': 'update',
			'data': {
				'editorFile': eutils.file_name(view),
				'patch': p
			}
		})
Ejemplo n.º 13
0
def send_patches(buf_id=None, p=None):
	if not buf_id or not p:
		return

	logger.debug(p)
	p = json.loads(p)
	view = eutils.view_for_buffer_id(buf_id)
	if p and view is not None:
		send_message({
			'action': 'update',
			'data': {
				'editorFile': eutils.file_name(view),
				'patch': p
			}
		})
Ejemplo n.º 14
0
def prepare_diff(buf_id):
    "Prepare buffer for diff'ing"
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        return

    if buf_id not in _diff_state:
        _diff_state[buf_id] = {
            'running': False,
            'required': False,
            'content': '',
            'start_time': 0
        }

    _diff_state[buf_id]['content'] = eutils.content(view)
Ejemplo n.º 15
0
def _start_patch(buf_id, patch, callback):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None:
		return

	content = eutils.content(view)

	@eutils.main_thread
	def _c(result):
		callback(buf_id, result)

		if buf_id in _patch_state:
			state = _patch_state[buf_id]
			state['running'] = False
			if state['patches']:
				patch(buf_id, None, callback)

	_patch_state[buf_id]['running'] = True
	with PyV8.JSLocker():
		threading.Thread(target=_run_patch, args=(content, patch, _c)).start()
Ejemplo n.º 16
0
def _start_patch(buf_id, patch, callback):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None:
        return

    content = eutils.content(view)

    @eutils.main_thread
    def _c(result):
        callback(buf_id, result)

        if buf_id in _patch_state:
            state = _patch_state[buf_id]
            state['running'] = False
            if state['patches']:
                patch(buf_id, None, callback)

    _patch_state[buf_id]['running'] = True
    with PyV8.JSLocker():
        threading.Thread(target=_run_patch, args=(content, patch, _c)).start()
Ejemplo n.º 17
0
def apply_patched_source(buf_id, content):
    view = eutils.view_for_buffer_id(buf_id)
    if view is None or content is None:
        return

    view.run_command('livestyle_replace_content', {'payload': content})
Ejemplo n.º 18
0
def apply_patched_source(buf_id, content):
	view = eutils.view_for_buffer_id(buf_id)
	if view is None or content is None:
		return

	view.run_command('livestyle_replace_content', {'payload': content})