Permalink
Browse files

Fixed some problems with type completion, and also update Readme, fin…

…ally also added some error handling, and made the Client/Server communication more smooth
  • Loading branch information...
1 parent 46a225a commit 953b2e231ad7f75045db3023aee01166a6a153c9 @StefanE committed Nov 26, 2010
View
@@ -22,14 +22,14 @@ Look at the downloads page to see latest release version [download](http://githu
### Misc
- Exact navigation (Enter name on class,object or trait). Should be improved to look more like the plugin OpenIt.
+- Scala REPL
##Current work
- Using a customized [Ensime Server](http://github.com/aemoncannon/ensime) as backend, a lot of stuff can be reused. If it is a success a lot of the planned features will be included in this implementation
- Currently Im have stopped my feature implementation and trying to stabilize the current features.
##Known problems (Should be moved to issues)
- Problems with autocompletion of imports...
-- Completion dont filter when user types characters
- Index should be optimized
##Planned
@@ -51,8 +51,4 @@ Look at the downloads page to see latest release version [download](http://githu
## How to use it
-Screencast showing the plugin features [Screencast](http://www.screencast.com/users/Adagioklez/folders/Jing/media/e2b209a5-fe6e-4109-a2ce-1f806f1edf95)
-
-Im currently planning to show its usefulness when using it for Lift development.
-
-More will be added later
+Here is the guide, and a link to a screencast (Guide)[http://groups.google.com/group/liftweb/browse_thread/thread/3e66b5a0b2791879]
@@ -63,6 +63,8 @@ info.save.message=You need to save before using Ensime
info.init.confirm.title=Confirm project path
info.init.confirm.message=Project will be initialized with the following path. Change if you want another path.
+error.ProjectViewer.title=ProjectViewer not active
+error.ProjectViewer.message=You need to create a project with projectviewer
error.noSBT.title=No SBT
error.noSBT.message=ProjectViewer project is not a SBT project error: "{0}"
@@ -7,6 +7,6 @@ object Global {
var currentView: View = _
var currentBuffer:Buffer = _
var initialized = false
- val actions: HashMap[Int,Function1[List[String],Unit]] = HashMap()
+ val actions: HashMap[Int,Function1[Any,Unit]] = HashMap()
var typeCheck = false
}
@@ -80,14 +80,17 @@ object ServerMessageHandler extends Actor {
}
}
+ case e:TypeCheckResult => {
+ action(e)
+ }
case BooleanMsg(value) => {
action(null)
}
case RefactorEffectMsg(value) => {
val id = ScalaSidekickPlugin.msgCounter
Global.actions += id -> {
- (_: List[String]) => action(null)
+ (_: Any) => action(null)
}
handleRefactoring(value, id)
}
@@ -182,7 +182,7 @@ trait ScalaProtocol extends Protocol {
def toWF(value: PackageMemberInfoLight): WireFormat = null
- def toWF(notelist: NoteList): WireFormat = null
+ def toWF(notelist: NoteList): WireFormat = TypeCheckResult(notelist.full,notelist.notes)
def toWF(config: ProjectConfig): WireFormat = null
}
@@ -13,6 +13,7 @@ import org.ensime.protocol.message.{TypecheckFile, TypeAtPoint, ScopeCompletion,
object CodeAssist {
def complete(textArea: JEditTextArea, view: View) {
+ println("Complete")
//TODO: Make some kind og save, else user should do it manually
val msgID = msgCounter()
@@ -32,34 +33,42 @@ object CodeAssist {
if (txt.contains(".")) {
val text = textArea.getText(caret - 1, 1)
if (text == ".") {
- textArea.setCaretPosition(caret,false)
+ textArea.setCaretPosition(caret, false)
msgToSend = TypeCompletion(file, caret - 1, "", msgID)
}
else {
textArea.goToPrevWord(true)
val curCaret = textArea.getCaretPosition
word = textArea.getText(curCaret, caret - curCaret)
- textArea.setCaretPosition(caret,true)
+ textArea.setCaretPosition(caret, true)
msgToSend = TypeCompletion(file, curCaret - 1, word, msgID)
}
}
else {
textArea.goToPrevWord(true)
val curCaret = textArea.getCaretPosition
word = textArea.getText(curCaret, caret - curCaret)
- textArea.setCaretPosition(caret,true)
+ textArea.setCaretPosition(caret, true)
msgToSend = ScopeCompletion(file, curCaret, word, false, msgID)
}
+ println("Test1")
//executes when answer returns
Global.actions += msgID -> {
- (list: List[String]) => {
- val pos = textArea.getLocationOnScreen
- val relpos = textArea.offsetToXY(caret)
- val position = new Point((pos.getX + relpos.getX + 40).toInt, (pos.getY + relpos.getY).toInt)
- val options = new Options(view.getTextArea, list)
- val completion = new CodeCompletion(view, position, list, word)
- completion.reset(options, true)
+ any: Any => {
+ any match {
+ case list: List[String] => {
+ println("Test22")
+ val pos = textArea.getLocationOnScreen
+ val relpos = textArea.offsetToXY(caret)
+ val position = new Point((pos.getX + relpos.getX + 40).toInt, (pos.getY + relpos.getY).toInt)
+ val options = new Options(view.getTextArea, list)
+ val completion = new CodeCompletion(view, position, list, word)
+ completion.reset(options, true)
+
+ }
+ case other => println("WTF" + other)
+ }
}
}
ClientSender ! msgToSend
@@ -74,10 +83,14 @@ object CodeAssist {
val id = msgCounter()
Global.actions += id -> {
- (list: List[String]) => {
- val Type = Array[AnyRef](list(0))
- //TODO: Should show in a nicer way
- GUIUtilities.message(null, "info.typeInfo", Type)
+ (any: Any) => {
+ any match {
+ case list: List[String] => {
+ val Type = Array[AnyRef](list(0))
+ //TODO: Should show in a nicer way
+ GUIUtilities.message(null, "info.typeInfo", Type)
+ }
+ }
}
}
ClientSender ! TypeAtPoint(file, currentCarPos, id)
@@ -28,46 +28,51 @@ object Navigation {
def navigateTo(view: View) {
createIndex(view)
- val request = GUIUtilities.input(null,"info.goto",null)
+ val request = GUIUtilities.input(null, "info.goto", null)
val elemList = index.filter(e => e.name == request)
- if(!elemList.isEmpty) {
+ if (!elemList.isEmpty) {
val goto = elemList(0)
- val buffer = jEdit.openFile(view,goto.path)
- try {
- val offset = view.getTextArea.getLineStartOffset(goto.line-1)
+ val buffer = jEdit.openFile(view, goto.path)
+ try
+ {
+ val offset = view.getTextArea.getLineStartOffset(goto.line - 1)
view.getTextArea.setCaretPosition(offset)
}
catch {
- case e:NullPointerException => println("NullPointer at GotoDefinition")
+ case e: NullPointerException => println("NullPointer at GotoDefinition")
}
}
else {
- GUIUtilities.message(null,"info.goto.unknown",null)
+ GUIUtilities.message(null, "info.goto.unknown", null)
}
}
-
+
def gotoDefinition(textArea: JEditTextArea, view: View) {
- setCurrent(textArea,view)
+ setCurrent(textArea, view)
val buffer = view.getBuffer
val path = buffer.getPath
val caret = textArea.getCaretPosition()
val msgID = msgCounter()
-
- Global.actions += msgID -> {(list:List[String]) => {
- //List with to elements: path to file and offset in file
- val path = list(0)
- val offset = list(1).toInt
- val buffer = jEdit.openFile(view,path)
- try {
- view.getTextArea.setCaretPosition(offset)
- }
- catch {
- case e:NullPointerException => println("NullPointer at GotoDefinition")
+
+ Global.actions += msgID -> {
+ (any: Any) => any match {
+ case list: List[String] => {
+ //List with to elements: path to file and offset in file
+ val path = list(0)
+ val offset = list(1).toInt
+ val buffer = jEdit.openFile(view, path)
+ try
+ {
+ view.getTextArea.setCaretPosition(offset)
+ }
+ catch {
+ case e: NullPointerException => println("NullPointer at GotoDefinition")
+ }
+ }
}
- } }
-
- ClientSender ! SymbolAtPoint(path,caret,msgID)
+ }
+ ClientSender ! SymbolAtPoint(path, caret, msgID)
}
def createIndex(view: View) {
@@ -115,11 +120,11 @@ object Navigation {
if (!indexdir.exists)
indexdir.mkdirs
- var f = new File(dirName + File.separator + INDEXFILENAME)
+ var f = new File(dirName + File.separator + INDEXFILENAME)
if (f.exists && f.canWrite) f.delete
f.createNewFile
- val writer = new BufferedWriter(new FileWriter(dirName + File.separator + INDEXFILENAME))
+ val writer = new BufferedWriter(new FileWriter(dirName + File.separator + INDEXFILENAME))
for (node <- index) {
writer.write(node + "\\n")
@@ -135,12 +140,12 @@ object Navigation {
var f = new File(dirName + File.separator + INDEXFILENAME)
if (f.exists && f.canRead) {
- val reader = new BufferedReader(new FileReader(dirName + File.separator + INDEXFILENAME))
+ val reader = new BufferedReader(new FileReader(dirName + File.separator + INDEXFILENAME))
for (node <- index) {
println("TEST:" + node)
val parts = reader.readLine().split(';')
- index ::= IndexEntry(parts(0),parts(1),parts(2),parts(3).toInt)
+ index ::= IndexEntry(parts(0), parts(1), parts(2), parts(3).toInt)
}
reader.close
}
@@ -150,7 +155,7 @@ object Navigation {
//Later remove duplicate code
}
- private def setCurrent(editor: JEditTextArea, view:View) {
+ private def setCurrent(editor: JEditTextArea, view: View) {
Global.currentView = view
Global.currentBuffer = view.getBuffer
}
@@ -31,7 +31,7 @@ object Refactoring {
val msgID = ScalaSidekickPlugin.msgCounter
Global.actions += msgID -> {
- (_: List[String]) => {
+ (_: Any) => {
buffer.reload(view)
}
}
@@ -53,7 +53,7 @@ object Refactoring {
val procId = ScalaSidekickPlugin.procCounter
Global.actions += msgId -> {
- (_: List[String]) => {
+ (_: Any) => {
view.getBuffer.reload(view)
}
}
@@ -19,7 +19,7 @@ object Reformat {
val path = view.getBuffer.getPath
val msgID = ScalaSidekickPlugin.msgCounter()
Global.actions += msgID -> {
- (_: List[String]) => {
+ (_: Any) => {
view.getBuffer.reload(view)
@@ -33,14 +33,19 @@ object ScalaSidekickPlugin {
MSGID
}
- def initProject(view: View) = {
- var projectPath = ProjectViewer.getActiveProject(view).getRootPath
+ def initProject(view: View) {
+ var project = ProjectViewer.getActiveProject(view)
+ if (project == null) {
+ GUIUtilities.message(null, "error.ProjectViewer", null)
+ return
+ }
+ var projectPath = project.getRootPath
Global.typeCheck = true
if (Global.initialized) {
Global.initialized = false
clearErrors
ClientSender ! InitProject("c:/Users/Stefan/Desktop/emacs-23.2/dist", "", "sbt", projectPath, msgCounter())
- GUIUtilities.message(null, "info.restarting", null)
+ GUIUtilities.message(null, "info.restarting", null)
}
else {
ClientReceiver.start
@@ -96,7 +101,37 @@ object ScalaSidekickPlugin {
def typeCheckProject(textArea: JEditTextArea, view: View) {
clearErrors()
Global.typeCheck = true
- ClientSender ! TypecheckAll(msgCounter())
+ val msgID = msgCounter()
+
+ Global.actions += msgID -> {
+ any: Any => {
+ any match {
+ case result: TypeCheckResult => {
+ val errors = new DefaultErrorSource("ProjectErrors")
+ val notes = result.notes
+ notes.foreach(note => {
+ if (note.severity != 0) {
+ val msg = note.msg
+ val start = note.beg
+ val length = note.end - start
+ val line = note.line
+ val path = note.file
+ val severity =
+ if (note.severity == 2) ErrorSource.ERROR
+ else ErrorSource.WARNING
+ errors.addError(severity, path, line - 1, start, 0, msg)
+ }
+ })
+ if (Global.typeCheck)
+ ErrorSource.registerErrorSource(errors)
+
+ Global.typeCheck = false
+ }
+ }
+ }
+ }
+
+ ClientSender ! TypecheckAll(msgID)
}
def Initialized(view: View) = {
@@ -140,7 +175,7 @@ class ScalaSidekickPlugin extends EBPlugin {
//ScalaSidekickPlugin.clearErrors()
ClientSender ! TypecheckFile(path, ScalaSidekickPlugin.msgCounter())
}
-
+
}
case other => println(other)
}
@@ -149,7 +184,7 @@ class ScalaSidekickPlugin extends EBPlugin {
override def start {
Navigation.loadIndex()
}
-
+
override def stop {
//Should stop scala shell?
}

0 comments on commit 953b2e2

Please sign in to comment.