Various improvements.

Change so library Haskell files are not passed to ghc-modi.
This commit is contained in:
Rik 2014-07-29 17:57:47 +02:00
parent 0db49cdaad
commit 4303ed6186
4 changed files with 48 additions and 7 deletions

View File

@ -21,7 +21,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.psi.util.PsiUtilBase
import com.intellij.psi.{PsiElement, PsiFile}
import com.powertuple.intellij.haskell.external.GhciModManager
import com.powertuple.intellij.haskell.util.{FileUtil, LineColumnPosition}
import com.powertuple.intellij.haskell.util.{ProjectUtil, FileUtil, LineColumnPosition}
import com.powertuple.intellij.haskell.{HaskellFile, HaskellLanguage, HaskellNotificationGroup}
import scala.util.{Failure, Success, Try}
@ -39,6 +39,12 @@ class ShowTypeAction extends AnAction {
if (editor == null) return
val psiFile = PsiUtilBase.getPsiFileInEditor(editor, CommonDataKeys.PROJECT.getData(context))
// Skip library files
if (!ProjectUtil.isProjectFile(psiFile)) {
return;
}
if (psiFile.getLanguage != HaskellLanguage.INSTANCE) return
FileUtil.saveFile(psiFile)

View File

@ -17,10 +17,8 @@
package com.powertuple.intellij.haskell.external
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.{Library, LibraryTablesRegistrar, LibraryTable}
/**
* TODO: Create separate ghc-modi instances for libraries.
*/
object GhciModManager {
private var reinit = false

View File

@ -23,7 +23,7 @@ import com.intellij.psi._
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.{PsiTreeUtil, PsiUtilCore}
import com.powertuple.intellij.haskell.external.GhciModManager
import com.powertuple.intellij.haskell.util.{FileUtil, HaskellFileIndex, LineColumnPosition}
import com.powertuple.intellij.haskell.util.{FileUtil, HaskellFileIndex, LineColumnPosition, ProjectUtil}
import com.powertuple.intellij.haskell.{HaskellFile, HaskellIcons, HaskellNotificationGroup}
import scala.util.{Failure, Success, Try}
@ -31,9 +31,15 @@ import scala.util.{Failure, Success, Try}
class HaskellVarReference(element: HaskellVar, textRange: TextRange) extends PsiReferenceBase[HaskellVar](element, textRange) {
override def resolve: PsiElement = {
val psiFile = myElement.getContainingFile
// Skip library files
if (!ProjectUtil.isProjectFile(psiFile)) {
return null;
}
FileUtil.saveAllFiles()
val psiFile = myElement.getContainingFile
val expression = myElement.getText.substring(textRange.getStartOffset, textRange.getEndOffset)
(for {
@ -106,12 +112,14 @@ class HaskellVarReference(element: HaskellVar, textRange: TextRange) extends Psi
private def ghcModiOutputToExpressionInfo(ghcModiOutput: String): Try[ExpressionInfo] = Try {
val GhcModiInfoPattern = """(.+)-- Defined at (.+):([\d]+):([\d]+)""".r
val GhcModiInfoLibraryPathPattern = """(.+)-- Defined in (.+):(.*).*""".r
val GhcModiInfoLibraryPattern = """(.+)-- Defined in (.+)""".r
ghcModiOutput match {
case GhcModiInfoPattern(typeSignature, filePath, lineNr, colNr) => LocalExpressionInfo(typeSignature.trim, filePath, lineNr.toInt, colNr.toInt)
case GhcModiInfoLibraryPathPattern(typeSignature, libraryName, filePath) => LibraryExpressionInfo(typeSignature.trim, findLibraryFilePath(filePath))
case GhcModiInfoLibraryPattern(typeSignature, modulePath) => LibraryExpressionInfo(typeSignature, findLibraryFilePath(modulePath))
case _ => throw new Exception(s"Unknown pattern for ghc-modi output: $ghcModiOutput")
case _ => throw new Exception(s"Unknown pattern for ghc-modi info output: $ghcModiOutput")
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2014 Rik van der Kleij
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.powertuple.intellij.haskell.util
import com.intellij.psi.PsiFile
import com.intellij.psi.search.GlobalSearchScope
object ProjectUtil {
def isProjectFile(psiFile: PsiFile): Boolean = {
val project = psiFile.getProject
val files = HaskellFileIndex.getFilesByName(project, psiFile.getName.split('.')(0), GlobalSearchScope.projectScope(project))
files.nonEmpty
}
}