Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support addQualifiedImport #7

Merged
merged 1 commit into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ bower_components/
node_modules/
output/
server.js
.psc-package/
.psc*
yarn.lock
21 changes: 16 additions & 5 deletions src/LanguageServer/IdePurescript/Imports.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import Control.Monad.Aff (Aff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Except (runExcept)
import Data.Either (Either(..))
import Data.Foldable (all)
import Data.Foreign (Foreign, readString, toForeign)
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
import Data.Nullable (toNullable)
import IdePurescript.Modules (ImportResult(..), addExplicitImport, addModuleImport)
import IdePurescript.Modules (ImportResult(..), addExplicitImport, addModuleImport, addQualifiedImport)
import IdePurescript.PscIde (getAvailableModules)
import IdePurescript.PscIdeServer (ErrorLevel(..), Notify)
import LanguageServer.DocumentStore (getDocument)
Expand All @@ -28,11 +30,16 @@ addCompletionImport log docs config state args = do
let shouldAddImport = autocompleteAddImport config
ServerState { port, modules, conn } = state
case port, (runExcept <<< readString) <$> args, shouldAddImport of
Just port', [ Right identifier, mod', qual', Right uri ], true -> do
Just port, [ Right identifier, mod, qual, Right uri ], true -> do
doc <- liftEff $ getDocument docs (DocumentUri uri)
version <- liftEff $ getVersion doc
text <- liftEff $ getText doc
{ state: modulesState', result } <- addExplicitImport modules port' uri text (hush mod') (hush qual') identifier
{ state: modulesState', result } <-
case hush mod, hush qual of
Just mod', Just qual' | all (not (isSameQualified mod' qual') <<< unwrap) modules.modules ->
addQualifiedImport modules port uri text mod' qual'
mod', qual' ->
addExplicitImport modules port uri text mod' qual' identifier
liftEff $ case result of
UpdatedImports newText -> do
let edit = makeMinimalWorkspaceEdit (DocumentUri uri) version text newText
Expand All @@ -52,6 +59,10 @@ addCompletionImport log docs config state args = do
where
successResult = toForeign $ toNullable Nothing

isSameQualified mod qual = case _ of
{ moduleName: mod', qualifier: Just qual'} -> mod == mod' && qual == qual'
_ -> false


addModuleImport' :: forall eff. Notify (MainEff eff) -> DocumentStore -> Settings -> ServerState (MainEff eff) -> Array Foreign -> Aff (MainEff eff) Foreign
addModuleImport' log docs config state args = do
Expand All @@ -63,7 +74,7 @@ addModuleImport' log docs config state args = do
text <- liftEff $ getText doc
fileName <- liftEff $ uriToFilename $ DocumentUri uri
res <- addModuleImport modules port' fileName text mod'
case res of
case res of
Just { result } -> do
let edit = makeMinimalWorkspaceEdit (DocumentUri uri) version text result
case conn, edit of
Expand All @@ -87,4 +98,4 @@ getAllModules log docs config state args =
toForeign <$> getAvailableModules port
_ -> do
liftEff $ log Error "Fail case"
pure $ toForeign []
pure $ toForeign []