Typed rules - #5025
Conversation
wz1000
left a comment
There was a problem hiding this comment.
Broadly looks good, some inputs need to be tightened up
Store SomeInput in Shake keys and route rule lookup helpers through typed RuleInput values instead of raw normalized file paths. This also updates tracing and no-file handling to work with the typed key representation.
Thread SomeFileInput, SomeHaskellInput, and ProjectHaskellInput through file store, HIE indexing, and module rules. Add a generic input reclassification helper so call sites can move between compatible typed rule inputs without bespoke wrappers.
Thread typed rule inputs through core Shake helpers, file-store state, dependency graph lookups, and LSP request handlers. Convert raw normalized paths at API boundaries so project, Haskell, and general file rules receive the appropriate input type.
Builds Ghcide, removes helpers that are not used or should not be used
Carry ProjectHaskellInput through dependency information, import lookup, reverse dependency traversal, HIE reads, and eval/reference paths instead of round-tripping through NormalizedFilePath. This keeps non-project Haskell inputs out of project-only rules while preserving the typed inputs needed by downstream Shake rules.
Track project Haskell inputs in session state, known targets, VFS-backed services, and caches. Migrate hover, notes, eval, and semantic token rules to use their typed inputs directly.
fendor
left a comment
There was a problem hiding this comment.
Thanks, this looks very nice! This is a nitpick review, so it is the intention to be done after the review is addressed. I have reviewed the ghcide changes, will review plugins soon.
Further, we agreed the following documentation is still missing and will be added:
* What are the existing rules?
* What is RuleInput?
* Why do we have RuleInput
* What is the design of RuleInput
Note [Hierarchical Inputs]
Note [RuleInput]
Reference these notes from various type classes and RuleInput type
* Helper functions need documentation
| toPriority :: PluginError -> Priority | ||
| toPriority (PluginInternalError _) = Error | ||
| toPriority (PluginInvalidParams _) = Warning | ||
| toPriority (PluginUnsupportedUriType _) = Warning |
There was a problem hiding this comment.
We might want to demote this to Debug. IIRC, a warning is displayed in the editor, but these errors will be perfectly sensible in the future, right?
@wz1000 opinions?
0e49c0f to
330adaf
Compare
144b524 to
ec6e677
Compare
| Within this hierarchy, a parent accepts all descendants. Upcasting wraps a child | ||
| in each parent constructor, then uses 'toInput' for 'SomeInput'; for example, | ||
| 'ProjectHaskellInput' -> 'SomeHaskellInput' -> 'SomeFileInput' -> 'SomeInput'. | ||
| 'fromInput' performs the checked downcast and succeeds only within its branch. |
There was a problem hiding this comment.
What does a parent accepts all descendants mean?
| case file of | ||
| SomeProjectHaskellInput projectFile -> | ||
| setFileModified (cmapWithPrio LogFileStore recorder) (VFSModified vfs) ide False projectFile action | ||
| _ -> setSomethingModified (VFSModified vfs) ide (fromNormalizedFilePath (inputFilePath file) ++ " (modified)") action |
There was a problem hiding this comment.
We shouldn't do anything here, rather log this case.
There was a problem hiding this comment.
@wz1000 What should we do in this case? Call setSomethingModified for completeness? We need to add it to the set of files of interest, but it might not need to record that it isn't the first time this non project haskell file was opened, right? 🤔
| case file of | ||
| SomeProjectHaskellInput projectFile -> | ||
| setFileModified (cmapWithPrio LogFileStore recorder) (VFSModified vfs) ide False projectFile action | ||
| _ -> setSomethingModified (VFSModified vfs) ide (fromNormalizedFilePath (inputFilePath file) ++ " (modified)") action |
There was a problem hiding this comment.
Should we set something modified here? What does this do?
| case file of | ||
| SomeProjectHaskellInput projectFile -> | ||
| setFileModified (cmapWithPrio LogFileStore recorder) (VFSModified vfs) ide True projectFile action | ||
| _ -> setSomethingModified (VFSModified vfs) ide (fromNormalizedFilePath (inputFilePath file) ++ " (modified)") action |
| let mbFile = case inputFingerprint input of | ||
| InputFile file -> Just file | ||
| _ -> Nothing |
There was a problem hiding this comment.
Move this into inProgress notification change
| -- * creating a dependency: If everything depends on GetModificationTime, we lose early cutoff | ||
| -- * creating bogus "file does not exists" diagnostics | ||
| | otherwise -> useWithoutDependency (GetModificationTime_ False) (toSomeFileInput file) | ||
| _ -> pure Nothing |
There was a problem hiding this comment.
Please list out all the possible cases here. I think that's better, even though the rhs is going to be identical for each
| -- GHC import paths are untyped and may include generated dependency roots; | ||
| -- retain only project Haskell inputs. |
There was a problem hiding this comment.
Which generated dependency roots? Where would this come from?
| resolveCompletion ide _pid comp@CompletionItem{_detail,_documentation,_data_} uri (CompletionResolveData _ needType (NameDetails mod occ)) = | ||
| do | ||
| file <- getNormalizedFilePathE uri | ||
| projectInput <- withExceptT (const PluginStaleResolve) $ classifyAsHaskell uri |
There was a problem hiding this comment.
Wrong classifier if completions only work with ProjectHaskell files, right?
| parseActions :: CI String -> [NormalizedFilePath] -> Action (Either Text [Bool]) | ||
| parseActions "typecheck" fps = Right . fmap isJust <$> uses TypeCheck fps | ||
| parseActions "getLocatedImports" fps = Right . fmap isJust <$> uses GetLocatedImports fps | ||
| parseActions "getmodsummary" fps = Right . fmap isJust <$> uses GetModSummary fps | ||
| parseActions "getmodsummarywithouttimestamps" fps = Right . fmap isJust <$> uses GetModSummaryWithoutTimestamps fps | ||
| parseActions "getparsedmodule" fps = Right . fmap isJust <$> uses GetParsedModule fps | ||
| parseActions "ghcsession" fps = Right . fmap isJust <$> uses GhcSession fps | ||
| parseActions "ghcsessiondeps" fps = Right . fmap isJust <$> uses GhcSessionDeps fps | ||
| parseActions "gethieast" fps = Right . fmap isJust <$> uses GetHieAst fps | ||
| parseActions "getFileContents" fps = Right . fmap isJust <$> uses GetFileContents fps | ||
| parseActions other _ = return $ Left $ "Cannot parse ide rule: " <> pack (original other) | ||
| parseActions :: CI String -> [SomeFileInput] -> Action (Either Text [Bool]) | ||
| parseActions action fps | ||
| | action == fromString "typecheck" | ||
| , Just pFiles <- traverse projectFile fps = | ||
| fmap (Right . map isJust) (uses TypeCheck pFiles) | ||
| where | ||
| projectFile (SomeFileHaskellInput (SomeProjectHaskellInput pFile)) = Just pFile | ||
| projectFile _ = Nothing | ||
| parseActions action fps = sequence <$> traverse (parseAction action) fps |
Introduces Hierarchical Typed Rules