Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
ce59acd1
Commit
ce59acd1
authored
Nov 15, 2018
by
David Kaltschmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extracted language provider variables for readibility
parent
ff0ed064
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
10 deletions
+15
-10
public/app/plugins/datasource/prometheus/language_provider.ts
+15
-10
No files found.
public/app/plugins/datasource/prometheus/language_provider.ts
View file @
ce59acd1
...
@@ -79,15 +79,23 @@ export default class PromQlLanguageProvider extends LanguageProvider {
...
@@ -79,15 +79,23 @@ export default class PromQlLanguageProvider extends LanguageProvider {
// Keep this DOM-free for testing
// Keep this DOM-free for testing
provideCompletionItems
({
prefix
,
wrapperClasses
,
text
,
value
}:
TypeaheadInput
,
context
?:
any
):
TypeaheadOutput
{
provideCompletionItems
({
prefix
,
wrapperClasses
,
text
,
value
}:
TypeaheadInput
,
context
?:
any
):
TypeaheadOutput
{
// Syntax spans have 3 classes by default. More indicate a recognized token
const
tokenRecognized
=
wrapperClasses
.
length
>
3
;
// Local text properties
// Local text properties
const
empty
=
value
.
document
.
text
.
length
===
0
;
const
empty
=
value
.
document
.
text
.
length
===
0
;
const
selectedLines
=
value
.
document
.
getTextsAtRangeAsArray
(
value
.
selection
);
const
selectedLines
=
value
.
document
.
getTextsAtRangeAsArray
(
value
.
selection
);
const
currentLine
=
selectedLines
.
length
===
1
?
selectedLines
[
0
]
:
null
;
const
currentLine
=
selectedLines
.
length
===
1
?
selectedLines
[
0
]
:
null
;
const
nextCharacter
=
currentLine
?
currentLine
.
text
[
value
.
selection
.
anchorOffset
]
:
null
;
const
nextCharacter
=
currentLine
?
currentLine
.
text
[
value
.
selection
.
anchorOffset
]
:
null
;
// Syntax spans have 3 classes by default. More indicate a recognized token
const
tokenRecognized
=
wrapperClasses
.
length
>
3
;
// Non-empty prefix, but not inside known token
const
prefixUnrecognized
=
prefix
&&
!
tokenRecognized
;
// Prevent suggestions in `function(|suffix)`
const
noSuffix
=
!
nextCharacter
||
nextCharacter
===
')'
;
// Empty prefix is safe if it does not immediately folllow a complete expression and has no text after it
const
safeEmptyPrefix
=
prefix
===
''
&&
!
text
.
match
(
/^
[\]
})
\s]
+$/
)
&&
noSuffix
;
// About to type next operand if preceded by binary operator
const
isNextOperand
=
text
.
match
(
/
[
+
\-
*
/
^%
]
/
);
// Determine candidates by CSS context
// Determine candidates by CSS context
if
(
_
.
includes
(
wrapperClasses
,
'context-range'
))
{
if
(
_
.
includes
(
wrapperClasses
,
'context-range'
))
{
// Suggestions for metric[|]
// Suggestions for metric[|]
...
@@ -96,16 +104,13 @@ export default class PromQlLanguageProvider extends LanguageProvider {
...
@@ -96,16 +104,13 @@ export default class PromQlLanguageProvider extends LanguageProvider {
// Suggestions for metric{|} and metric{foo=|}, as well as metric-independent label queries like {|}
// Suggestions for metric{|} and metric{foo=|}, as well as metric-independent label queries like {|}
return
this
.
getLabelCompletionItems
.
apply
(
this
,
arguments
);
return
this
.
getLabelCompletionItems
.
apply
(
this
,
arguments
);
}
else
if
(
_
.
includes
(
wrapperClasses
,
'context-aggregation'
))
{
}
else
if
(
_
.
includes
(
wrapperClasses
,
'context-aggregation'
))
{
// Suggestions for sum(metric) by (|)
return
this
.
getAggregationCompletionItems
.
apply
(
this
,
arguments
);
return
this
.
getAggregationCompletionItems
.
apply
(
this
,
arguments
);
}
else
if
(
empty
)
{
}
else
if
(
empty
)
{
// Suggestions for empty query field
return
this
.
getEmptyCompletionItems
(
context
||
{});
return
this
.
getEmptyCompletionItems
(
context
||
{});
}
else
if
(
}
else
if
(
prefixUnrecognized
||
safeEmptyPrefix
||
isNextOperand
)
{
// Show default suggestions in a couple of scenarios
// Show term suggestions in a couple of scenarios
(
prefix
&&
!
tokenRecognized
)
||
// Non-empty prefix, but not inside known token
// Empty prefix, but not directly following a closing brace (e.g., `]|`), or not succeeded by anything except a closing parens, e.g., `sum(|)`
(
prefix
===
''
&&
!
text
.
match
(
/^
[\]
})
\s]
+$/
)
&&
(
!
nextCharacter
||
nextCharacter
===
')'
))
||
text
.
match
(
/
[
+
\-
*
/
^%
]
/
)
// Anything after binary operator
)
{
return
this
.
getTermCompletionItems
();
return
this
.
getTermCompletionItems
();
}
}
...
...
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