Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
aadb4c7c
Commit
aadb4c7c
authored
Nov 04, 2013
by
Adam Vogt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make completion lexing slightly more reliable
parent
26630501
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
12 deletions
+25
-12
Completion.hs
IHaskell/Completion.hs
+25
-12
No files found.
IHaskell/Completion.hs
View file @
aadb4c7c
{-# LANGUAGE PatternGuards #-}
{- | Description : generates tab-completion options
very approximate completion. Seems to generate what is required b
y
<http://ipython.org/ipython-doc/dev/development/messaging.html#complete>,
but for whatever reason nothing gets added when the liftIO below prints
stuff like:
context-insensitive completion for what is probabl
y
the identifier under the cursor.
[@Known issues@]
> {"status":"ok","text":"import Data hea","matches":["head"]}
> import Data.Lef<tab>
> System.IO.h<tab>
> Just.he<tab>
The first should not complete to Left. The second should only
include things like System.IO.hPutStrLn, not head. Qualified
names should not be confused by the third option.
When the cursor is after the hea, and you press tab.
-}
module
IHaskell.Completion
(
makeCompletions
)
where
...
...
@@ -25,6 +30,7 @@ import Data.List.Split.Internals
import
Data.Aeson
import
IHaskell.Message.Writer
import
qualified
Data.ByteString.Lazy
as
L
import
Data.Maybe
makeCompletions
::
GHC
.
GhcMonad
m
=>
MessageHeader
->
Message
->
m
Message
...
...
@@ -36,20 +42,27 @@ makeCompletions replyHeader (CompleteRequest hdr code line pos) = do
let
candidate
=
getWordAt
(
toString
line
)
pos
opts
|
Just
cand
<-
candidate
=
filter
(
cand
`
isPrefixOf
`)
$
map
(
showPpr
fs
)
ns
|
otherwise
=
[]
matched_text
=
fromString
$
maybe
""
id
candidate
matched_text
=
fromString
$
fromMaybe
""
candidate
let
reply
=
CompleteReply
replyHeader
(
map
fromString
opts
)
matched_text
line
True
liftIO
(
L
.
putStrLn
$
encode
$
toJSON
reply
)
return
reply
return
$
CompleteReply
replyHeader
(
map
fromString
opts
)
matched_text
line
True
-- there are better ways to accomplish this
-- maybe there are better ways to be sure we're getting only
-- the whole word under the cursor...
getWordAt
::
String
->
Int
->
Maybe
String
getWordAt
xs
n
=
fmap
(
map
fst
)
$
find
(
any
(
==
n
)
.
map
snd
)
$
split
(
defaultSplitter
{
delimiter
=
Delimiter
[
(
==
)
' '
.
fst
],
delimiter
=
Delimiter
[
isDelim
.
fst
],
condensePolicy
=
Condense
})
(
zip
xs
[
1
..
])
where
isDelim
|
x
:
_
<-
Data
.
List
.
drop
(
max
0
(
n
-
1
))
xs
=
\
s
->
(
s
`
elem
`
neverIdent
)
||
if
isSymbol
x
then
isAlpha
s
else
isSymbol
s
|
otherwise
=
\
s
->
s
`
elem
`
neverIdent
-- these (and others?) are never part of an identifier
-- except for the dot (qualified names are tricky)
neverIdent
=
"
\t
(),{}[]
\\
'
\"
`."
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment