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
341a5cd1
Commit
341a5cd1
authored
Nov 04, 2013
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #33 from aavogt/master
make completion lexing slightly more reliable
parents
e1151a0b
aadb4c7c
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 @
341a5cd1
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE PatternGuards #-}
{- | Description : generates tab-completion options
{- | Description : generates tab-completion options
very approximate completion. Seems to generate what is required b
y
context-insensitive completion for what is probabl
y
<http://ipython.org/ipython-doc/dev/development/messaging.html#complete>,
the identifier under the cursor.
but for whatever reason nothing gets added when the liftIO below prints
stuff like:
[@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
module
IHaskell.Completion
(
makeCompletions
)
where
...
@@ -25,6 +30,7 @@ import Data.List.Split.Internals
...
@@ -25,6 +30,7 @@ import Data.List.Split.Internals
import
Data.Aeson
import
Data.Aeson
import
IHaskell.Message.Writer
import
IHaskell.Message.Writer
import
qualified
Data.ByteString.Lazy
as
L
import
qualified
Data.ByteString.Lazy
as
L
import
Data.Maybe
makeCompletions
makeCompletions
::
GHC
.
GhcMonad
m
=>
MessageHeader
->
Message
->
m
Message
::
GHC
.
GhcMonad
m
=>
MessageHeader
->
Message
->
m
Message
...
@@ -36,20 +42,27 @@ makeCompletions replyHeader (CompleteRequest hdr code line pos) = do
...
@@ -36,20 +42,27 @@ makeCompletions replyHeader (CompleteRequest hdr code line pos) = do
let
candidate
=
getWordAt
(
toString
line
)
pos
let
candidate
=
getWordAt
(
toString
line
)
pos
opts
|
Just
cand
<-
candidate
=
filter
(
cand
`
isPrefixOf
`)
$
map
(
showPpr
fs
)
ns
opts
|
Just
cand
<-
candidate
=
filter
(
cand
`
isPrefixOf
`)
$
map
(
showPpr
fs
)
ns
|
otherwise
=
[]
|
otherwise
=
[]
matched_text
=
fromString
$
maybe
""
id
candidate
matched_text
=
fromString
$
fromMaybe
""
candidate
let
reply
=
CompleteReply
replyHeader
(
map
fromString
opts
)
matched_text
line
True
return
$
CompleteReply
replyHeader
(
map
fromString
opts
)
matched_text
line
True
liftIO
(
L
.
putStrLn
$
encode
$
toJSON
reply
)
return
reply
-- 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
::
String
->
Int
->
Maybe
String
getWordAt
xs
n
=
getWordAt
xs
n
=
fmap
(
map
fst
)
$
fmap
(
map
fst
)
$
find
(
any
(
==
n
)
.
map
snd
)
$
find
(
any
(
==
n
)
.
map
snd
)
$
split
(
defaultSplitter
{
split
(
defaultSplitter
{
delimiter
=
Delimiter
[
(
==
)
' '
.
fst
],
delimiter
=
Delimiter
[
isDelim
.
fst
],
condensePolicy
=
Condense
})
condensePolicy
=
Condense
})
(
zip
xs
[
1
..
])
(
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