Skip to content

Commit

Permalink
Merge pull request #23 from tomv564/more_tests
Browse files Browse the repository at this point in the history
Turn off some features on non-Haskell views, add more tests
  • Loading branch information
tomv564 committed Oct 21, 2015
2 parents 583aad5 + ec53f16 commit 036f4d9
Show file tree
Hide file tree
Showing 20 changed files with 789 additions and 280 deletions.
2 changes: 1 addition & 1 deletion application_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sublime_plugin

from SublimeStackIDE.stack_ide_manager import *
from SublimeStackIDE.stack_ide_manager import StackIDEManager


class RestartStackIde(sublime_plugin.ApplicationCommand):
Expand Down
44 changes: 31 additions & 13 deletions event_listeners.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import sublime_plugin, sublime
try:
import sublime_plugin, sublime
except ImportError:
from test.stubs import sublime, sublime_plugin

from SublimeStackIDE.utility import *
from SublimeStackIDE.req import *
from SublimeStackIDE.log import *
from SublimeStackIDE.win import *
from SublimeStackIDE.stack_ide import *
from SublimeStackIDE.stack_ide_manager import *
from SublimeStackIDE import response as res
import sys, os
sys.path.append(os.path.dirname(os.path.realpath(__file__)))

from utility import is_haskell_view, relative_view_file_name, span_from_view_selection
from req import Req
from win import Win
from stack_ide_manager import StackIDEManager, send_request
import response as res


class StackIDESaveListener(sublime_plugin.EventListener):
Expand All @@ -15,6 +19,10 @@ class StackIDESaveListener(sublime_plugin.EventListener):
then request a report of source errors.
"""
def on_post_save(self, view):

if not is_haskell_view(view):
return

if not StackIDEManager.is_running(view.window()):
return

Expand All @@ -26,17 +34,21 @@ class StackIDETypeAtCursorHandler(sublime_plugin.EventListener):
time it changes position.
"""
def on_selection_modified(self, view):
if not view:

if not is_haskell_view(view):
return
if not StackIDEManager.is_running(view.window()):

window = view.window()
if not StackIDEManager.is_running(window):
return

# Only try to get types for views into files
# (rather than e.g. the find field or the console pane)
if view.file_name():
# Uncomment to see the scope at the cursor:
# Log.debug(view.scope_name(view.sel()[0].begin()))
request = Req.get_exp_types(span_from_view_selection(view))
send_request(view, request, Win(view).highlight_type)
send_request(window, request, Win(window).highlight_type)


class StackIDEAutocompleteHandler(sublime_plugin.EventListener):
Expand All @@ -48,14 +60,20 @@ def __init__(self):
self.returned_completions = []

def on_query_completions(self, view, prefix, locations):
if not StackIDEManager.is_running(view.window()):

if not is_haskell_view(view):
return

window = view.window()
if not StackIDEManager.is_running(window):
return

# Check if this completion query is due to our refreshing the completions list
# after receiving a response from stack-ide, and if so, don't send
# another request for completions.
if not view.settings().get("refreshing_auto_complete"):
request = Req.get_autocompletion(filepath=relative_view_file_name(view),prefix=prefix)
send_request(view, request, Win(view).update_completions)
send_request(window, request, Win(window).update_completions)

# Clear the flag to uninhibit future completion queries
view.settings().set("refreshing_auto_complete", False)
Expand Down
8 changes: 8 additions & 0 deletions req.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def update_session_includes(filepaths):
]
}

@staticmethod
def update_session():
return { "tag":"RequestUpdateSession", "contents": []}

@staticmethod
def get_source_errors():
return {"tag": "RequestGetSourceErrors", "contents":[]}
Expand All @@ -22,6 +26,10 @@ def get_exp_types(exp_span):
def get_exp_info(exp_span):
return { "tag": "RequestGetSpanInfo", "contents": exp_span}

@staticmethod
def get_shutdown():
return {"tag":"RequestShutdownSession", "contents":[]}

@staticmethod
def get_autocompletion(filepath,prefix):
return {
Expand Down
4 changes: 2 additions & 2 deletions response.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def parse_update_session(contents):
progress = contents.get('contents')
return str(progress.get("progressParsedMsg"))
elif tag == "UpdateStatusDone":
return "Session started."
return " "
elif tag == "UpdateStatusRequiredRestart":
return "Restarting session..."
return "Starting session..."


def parse_source_errors(contents):
Expand Down
75 changes: 0 additions & 75 deletions span.py

This file was deleted.

Loading

0 comments on commit 036f4d9

Please sign in to comment.