Skip to content

Commit

Permalink
Fix #66; Fix #67; Fix Add Import styling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
halohalospecial committed Mar 17, 2017
1 parent 7a53430 commit 67c7255
Show file tree
Hide file tree
Showing 12 changed files with 446 additions and 390 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 5.3.4
* Fix issue when deleting `.elm` files. (#66). Thanks to @pacbeckh for reporting!
* Fix `Add Import` styling issue.
* Remove package docs download failure messages from the Sidekick panel and show in a notification popup instead (#67). Thanks to @vladpazych for reporting!

## 5.3.3
* Add some more basic caching for autocomplete suggestions.
* Sort identically-named suggestions by their module names.
Expand Down
71 changes: 44 additions & 27 deletions elm/Indexer.elm
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ type alias ExternalHints =

type alias LocalHints =
{ topLevelHints : List Hint
, argHints : List Hint
, variableHints : List Hint
}


Expand Down Expand Up @@ -398,7 +398,25 @@ update msg model =
( successes ++ [ ( moduleDocsList, ( dependency, jsonString ) ) ], failures )

Err message ->
( successes, failures ++ [ toString message ++ " " ++ toPackageUri dependency ++ "documentation.json" ] )
let
errorDetails =
case message of
Http.BadUrl string ->
"BadUrl " ++ string

Http.Timeout ->
"Timeout"

Http.NetworkError ->
"NetworkError"

Http.BadStatus { status } ->
"BadStatus " ++ toString status.code ++ " " ++ status.message

Http.BadPayload _ { status } ->
"BadPayload " ++ toString status.code ++ " " ++ status.message
in
( successes, failures ++ [ toPackageUri dependency ++ "documentation.json (" ++ errorDetails ++ ")" ] )
)
( [], [] )
(List.map2 (,) dependencies result)
Expand All @@ -415,7 +433,7 @@ update msg model =
, Cmd.batch
([ docsDownloadedCmd loadedDependenciesAndJson ]
++ (if List.length failures > 0 then
[ downloadDocsFailedCmd (String.join "\n" failures) ]
[ downloadDocsFailedCmd (String.join "\n---\n" failures) ]
else
[]
)
Expand Down Expand Up @@ -1261,7 +1279,7 @@ getLocalHints filePath activeFileContents activeFileTokens =
{ topLevelHints =
getExposedAndUnexposedHints False filePath selfImport [ activeFileContents.moduleDocs ]
|> Tuple.first
, argHints =
, variableHints =
activeFileTokens
|> Dict.values
|> List.concat
Expand Down Expand Up @@ -1306,7 +1324,7 @@ getExternalAndLocalHints isGlobal maybeActiveFile projectFileContentsDict projec

Nothing ->
{ external = Just { importedHints = [], unimportedHints = [] }
, local = Just { topLevelHints = [], argHints = [] }
, local = Just { topLevelHints = [], variableHints = [] }
}


Expand All @@ -1328,10 +1346,10 @@ getHintsForPartial partial maybeInferredTipe preceedingToken isRegex isFiltered
Nothing ->
getExternalAndLocalHints isGlobal maybeActiveFile projectFileContentsDict projectDependencies packageDocs Nothing Nothing activeFileTokens

( exposedAndTopLevelHints, unexposedHints, argHints ) =
( exposedAndTopLevelHints, unexposedHints, variableHints ) =
case ( external, local ) of
( Just external, Just local ) ->
( external.importedHints ++ local.topLevelHints, external.unimportedHints, local.argHints )
( external.importedHints ++ local.topLevelHints, external.unimportedHints, local.variableHints )

_ ->
( [], [], [] )
Expand All @@ -1345,8 +1363,8 @@ getHintsForPartial partial maybeInferredTipe preceedingToken isRegex isFiltered
filteredUnexposedHints =
filterHintsByName partial maybeInferredTipe isFiltered isRegex unexposedHints

filteredArgHints =
filterHintsByName partial maybeInferredTipe isFiltered isRegex argHints
filteredVariableHints =
filterHintsByName partial maybeInferredTipe isFiltered isRegex variableHints

hints =
case maybeInferredTipe of
Expand All @@ -1355,8 +1373,8 @@ getHintsForPartial partial maybeInferredTipe preceedingToken isRegex isFiltered
partitionHints hints =
List.partition (partitionByTipe tipeString preceedingToken) hints

( argHintsCompatible, argHintsNotCompatible ) =
partitionHints filteredArgHints
( variableHintsCompatible, variableHintsNotCompatible ) =
partitionHints filteredVariableHints

( defaultHintsCompatible, defaultHintsNotCompatible ) =
partitionHints filteredDefaultHints
Expand All @@ -1367,20 +1385,20 @@ getHintsForPartial partial maybeInferredTipe preceedingToken isRegex isFiltered
( unexposedHintsCompatible, unexposedHintsNotCompatible ) =
partitionHints filteredUnexposedHints
in
sortHintsByScore tipeString preceedingToken argHintsCompatible
sortHintsByScore tipeString preceedingToken variableHintsCompatible
++ sortHintsByScore tipeString preceedingToken defaultHintsCompatible
++ sortHintsByScore tipeString preceedingToken exposedHintsCompatible
++ sortHintsByScore tipeString preceedingToken unexposedHintsCompatible
++ (sortHintsByName
(filterTypeIncompatibleHints partial isFiltered isRegex argHintsNotCompatible
(filterTypeIncompatibleHints partial isFiltered isRegex variableHintsNotCompatible
++ filterTypeIncompatibleHints partial isFiltered isRegex defaultHintsNotCompatible
++ filterTypeIncompatibleHints partial isFiltered isRegex exposedHintsNotCompatible
)
++ sortHintsByName (filterTypeIncompatibleHints partial isFiltered isRegex unexposedHintsNotCompatible)
)

Nothing ->
(filteredArgHints
(filteredVariableHints
++ filteredDefaultHints
++ filteredExposedHints
++ filteredUnexposedHints
Expand Down Expand Up @@ -3064,11 +3082,11 @@ getActiveFileTokens maybeActiveFile maybeActiveTopLevel projectFileContentsDict
List.map2 (,) args (getTipeParts tipe)
)

argHints =
argumentHints =
case maybeActiveTopLevel of
Just activeTopLevel ->
List.concatMap
(topLevelArgToHints activeTopLevel
(topLevelArgToHints
filePath
( maybeActiveFile, projectFileContentsDict, projectDependencies, packageDocs )
topLevelTokens
Expand All @@ -3079,7 +3097,7 @@ getActiveFileTokens maybeActiveFile maybeActiveTopLevel projectFileContentsDict
[]

activeFileTokens =
(argHints
(argumentHints
++ (defaultSuggestions
|> List.filter (\hint -> hint.comment /= "")
|> List.map (\hint -> ( hint.name, hint ))
Expand Down Expand Up @@ -3569,8 +3587,8 @@ getFilteredHints activeFilePath moduleDocs importData =
++ moduleToHints moduleDocs importData


topLevelArgToHints : ActiveTopLevel -> SourcePath -> ( Maybe ActiveFile, ProjectFileContentsDict, ProjectDependencies, List ModuleDocs ) -> TokenDict -> ( String, TipeString ) -> List ( String, Hint )
topLevelArgToHints activeTopLevel parentSourcePath ( maybeActiveFile, projectFileContentsDict, projectDependencies, packageDocs ) topLevelTokens ( name, tipeString ) =
topLevelArgToHints : SourcePath -> ( Maybe ActiveFile, ProjectFileContentsDict, ProjectDependencies, List ModuleDocs ) -> TokenDict -> ( String, TipeString ) -> List ( String, Hint )
topLevelArgToHints parentSourcePath ( maybeActiveFile, projectFileContentsDict, projectDependencies, packageDocs ) topLevelTokens ( name, tipeString ) =
let
getHint ( name, tipeString ) =
let
Expand Down Expand Up @@ -3600,14 +3618,11 @@ topLevelArgToHints activeTopLevel parentSourcePath ( maybeActiveFile, projectFil
Dict.get field (getRecordTipeParts tipeString |> Dict.fromList)
|> Maybe.map
(\tipeString ->
getRecordFieldTokensRecur field
getRecordFieldTokens field
tipeString
parentSourcePath
( maybeActiveFile, projectFileContentsDict, projectDependencies, packageDocs )
topLevelTokens
True
Nothing
Set.empty
)
)
|> List.concat
Expand All @@ -3625,19 +3640,21 @@ topLevelArgToHints activeTopLevel parentSourcePath ( maybeActiveFile, projectFil
[]

( False, _ ) ->
getRecordFieldTokensRecur name
getRecordFieldTokens name
tipeString
parentSourcePath
( maybeActiveFile, projectFileContentsDict, projectDependencies, packageDocs )
topLevelTokens
True
Nothing
Set.empty
in
tipes
|> List.concatMap getHint


getRecordFieldTokens : String -> TipeString -> SourcePath -> ( Maybe ActiveFile, ProjectFileContentsDict, ProjectDependencies, List ModuleDocs ) -> TokenDict -> List ( String, TipeString )
getRecordFieldTokens name tipeString parentSourcePath ( maybeActiveFile, projectFileContentsDict, projectDependencies, packageDocs ) topLevelTokens =
getRecordFieldTokensRecur name tipeString parentSourcePath ( maybeActiveFile, projectFileContentsDict, projectDependencies, packageDocs ) topLevelTokens True Nothing Set.empty


getRecordFieldTokensRecur : String -> TipeString -> SourcePath -> ( Maybe ActiveFile, ProjectFileContentsDict, ProjectDependencies, List ModuleDocs ) -> TokenDict -> Bool -> Maybe String -> Set.Set String -> List ( String, TipeString )
getRecordFieldTokensRecur name tipeString parentSourcePath ( maybeActiveFile, projectFileContentsDict, projectDependencies, packageDocs ) topLevelTokens shouldAddSelf maybeRootTipeString visitedSourcePaths =
(if shouldAddSelf then
Expand Down
16 changes: 8 additions & 8 deletions elm/Sidekick.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ subscriptions model =
, activeFileChangedSub ActiveFileChanged
, docsReadSub (\_ -> DocsRead)
, docsDownloadedSub (\_ -> DocsDownloaded)
, downloadDocsFailedSub DownloadDocsFailed
-- , downloadDocsFailedSub DownloadDocsFailed
, readingPackageDocsSub (\_ -> ReadingPackageDocs)
, downloadingPackageDocsSub (\_ -> DownloadingPackageDocs)
, configChangedSub ConfigChanged
Expand All @@ -48,7 +48,8 @@ port docsReadSub : (() -> msg) -> Sub msg
port docsDownloadedSub : (() -> msg) -> Sub msg


port downloadDocsFailedSub : (String -> msg) -> Sub msg

-- port downloadDocsFailedSub : (String -> msg) -> Sub msg


port readingPackageDocsSub : (() -> msg) -> Sub msg
Expand Down Expand Up @@ -129,7 +130,7 @@ type Msg
| ActiveFileChanged (Maybe ActiveFile)
| DocsRead
| DocsDownloaded
| DownloadDocsFailed String
-- | DownloadDocsFailed String
| ReadingPackageDocs
| DownloadingPackageDocs
| GoToDefinition String
Expand Down Expand Up @@ -159,11 +160,10 @@ update msg model =
, Cmd.none
)

DownloadDocsFailed message ->
( { model | note = "Failed to download package docs:\n" ++ message }
, Cmd.none
)

-- DownloadDocsFailed message ->
-- ( { model | note = "Failed to download package docs:\n" ++ message }
-- , Cmd.none
-- )
ReadingPackageDocs ->
( { model | note = "Reading package docs..." }
, Cmd.none
Expand Down
Loading

0 comments on commit 67c7255

Please sign in to comment.