Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
CodeMirror
Commits
51696b48
Commit
51696b48
authored
12 years ago
by
robertop23
Committed by
Marijn Haverbeke
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Create python-hint.js
parent
023f240a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/util/python-hint.js
+93
-0
93 additions, 0 deletions
lib/util/python-hint.js
with
93 additions
and
0 deletions
lib/util/python-hint.js
0 → 100644
+
93
−
0
View file @
51696b48
(
function
()
{
function
forEach
(
arr
,
f
)
{
for
(
var
i
=
0
,
e
=
arr
.
length
;
i
<
e
;
++
i
)
f
(
arr
[
i
]);
}
function
arrayContains
(
arr
,
item
)
{
if
(
!
Array
.
prototype
.
indexOf
)
{
var
i
=
arr
.
length
;
while
(
i
--
)
{
if
(
arr
[
i
]
===
item
)
{
return
true
;
}
}
return
false
;
}
return
arr
.
indexOf
(
item
)
!=
-
1
;
}
function
scriptHint
(
editor
,
_keywords
,
getToken
)
{
// Find the token at the cursor
var
cur
=
editor
.
getCursor
(),
token
=
getToken
(
editor
,
cur
),
tprop
=
token
;
// If it's not a 'word-style' token, ignore the token.
if
(
!
/^
[\w
$_
]
*$/
.
test
(
token
.
string
))
{
token
=
tprop
=
{
start
:
cur
.
ch
,
end
:
cur
.
ch
,
string
:
""
,
state
:
token
.
state
,
className
:
token
.
string
==
"
:
"
?
"
python-type
"
:
null
};
}
if
(
!
context
)
var
context
=
[];
context
.
push
(
tprop
);
var
completionList
=
getCompletions
(
token
,
context
);
completionList
=
completionList
.
sort
();
//prevent autocomplete for last word, instead show dropdown with one word
if
(
completionList
.
length
==
1
)
{
completionList
.
push
(
"
"
);
}
return
{
list
:
completionList
,
from
:
{
line
:
cur
.
line
,
ch
:
token
.
start
},
to
:
{
line
:
cur
.
line
,
ch
:
token
.
end
}};
}
CodeMirror
.
pythonHint
=
function
(
editor
)
{
return
scriptHint
(
editor
,
pythonKeywordsU
,
function
(
e
,
cur
)
{
return
e
.
getTokenAt
(
cur
);});
};
var
pythonKeywords
=
"
and del from not while as elif global or with assert else if pass yield
"
+
"
break except import print class exec in raise continue finally is return def for lambda try
"
;
var
pythonKeywordsL
=
pythonKeywords
.
split
(
"
"
);
var
pythonKeywordsU
=
pythonKeywords
.
toUpperCase
().
split
(
"
"
);
var
pythonBuiltins
=
"
abs divmod input open staticmethod all enumerate int ord str
"
+
"
any eval isinstance pow sum basestring execfile issubclass print super
"
+
"
bin file iter property tuple bool filter len range type
"
+
"
bytearray float list raw_input unichr callable format locals reduce unicode
"
+
"
chr frozenset long reload vars classmethod getattr map repr xrange
"
+
"
cmp globals max reversed zip compile hasattr memoryview round __import__
"
+
"
complex hash min set apply delattr help next setattr buffer
"
+
"
dict hex object slice coerce dir id oct sorted intern
"
;
var
pythonBuiltinsL
=
pythonBuiltins
.
split
(
"
"
).
join
(
"
()
"
).
split
(
"
"
);
var
pythonBuiltinsU
=
pythonBuiltins
.
toUpperCase
().
split
(
"
"
).
join
(
"
()
"
).
split
(
"
"
);
function
getCompletions
(
token
,
context
)
{
var
found
=
[],
start
=
token
.
string
;
function
maybeAdd
(
str
)
{
if
(
str
.
indexOf
(
start
)
==
0
&&
!
arrayContains
(
found
,
str
))
found
.
push
(
str
);
}
function
gatherCompletions
(
obj
)
{
forEach
(
pythonBuiltinsL
,
maybeAdd
);
forEach
(
pythonBuiltinsU
,
maybeAdd
);
forEach
(
pythonKeywordsL
,
maybeAdd
);
forEach
(
pythonKeywordsU
,
maybeAdd
);
}
if
(
context
)
{
// If this is a property, see if it belongs to some object we can
// find in the current environment.
var
obj
=
context
.
pop
(),
base
;
if
(
obj
.
type
==
"
variable
"
)
base
=
obj
.
string
;
else
if
(
obj
.
type
==
"
variable-3
"
)
base
=
"
:
"
+
obj
.
string
;
while
(
base
!=
null
&&
context
.
length
)
base
=
base
[
context
.
pop
().
string
];
if
(
base
!=
null
)
gatherCompletions
(
base
);
}
return
found
;
}
})();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment