-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Console] Refactor and cleanup of public and server #60513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jloleysens
merged 6 commits into
elastic:master
from
jloleysens:refactor/console/cleanup
Mar 19, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fe329a5
Clean up use of ace in autocomplete in public
jloleysens 834c0aa
Added TODO in lib/kb (console public)
jloleysens b16eb50
Server-side cleanup
jloleysens 87ddc60
Fix types
jloleysens 3c1d020
Merge branch 'master' of github.com:elastic/kibana into refactor/cons…
jloleysens 5886a2a
Small refactor
jloleysens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,9 @@ | |
| */ | ||
|
|
||
| import _ from 'lodash'; | ||
| import ace, { Editor as AceEditor, IEditSession } from 'brace'; | ||
| import { i18n } from '@kbn/i18n'; | ||
|
|
||
| // TODO: All of these imports need to be moved to the core editor so that it can inject components from there. | ||
| import { | ||
| getTopLevelUrlCompleteComponents, | ||
| getEndpointBodyCompleteComponents, | ||
|
|
@@ -39,7 +39,7 @@ import { createTokenIterator } from '../../application/factories'; | |
|
|
||
| import { Position, Token, Range, CoreEditor } from '../../types'; | ||
|
|
||
| let LAST_EVALUATED_TOKEN: any = null; | ||
| let lastEvaluatedToken: any = null; | ||
|
|
||
| function isUrlParamsToken(token: any) { | ||
| switch ((token || {}).type) { | ||
|
|
@@ -889,7 +889,7 @@ export default function({ coreEditor: editor, parser }: { coreEditor: CoreEditor | |
|
|
||
| if (!currentToken) { | ||
| if (pos.lineNumber === 1) { | ||
| LAST_EVALUATED_TOKEN = null; | ||
| lastEvaluatedToken = null; | ||
| return; | ||
| } | ||
| currentToken = { position: { column: 0, lineNumber: 0 }, value: '', type: '' }; // empty row | ||
|
|
@@ -902,26 +902,26 @@ export default function({ coreEditor: editor, parser }: { coreEditor: CoreEditor | |
| if (parser.isEmptyToken(nextToken)) { | ||
| // Empty line, or we're not on the edge of current token. Save the current position as base | ||
| currentToken.position.column = pos.column; | ||
| LAST_EVALUATED_TOKEN = currentToken; | ||
| lastEvaluatedToken = currentToken; | ||
| } else { | ||
| nextToken.position.lineNumber = pos.lineNumber; | ||
| LAST_EVALUATED_TOKEN = nextToken; | ||
| lastEvaluatedToken = nextToken; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (!LAST_EVALUATED_TOKEN) { | ||
| LAST_EVALUATED_TOKEN = currentToken; | ||
| if (!lastEvaluatedToken) { | ||
| lastEvaluatedToken = currentToken; | ||
| return; // wait for the next typing. | ||
| } | ||
|
|
||
| if ( | ||
| LAST_EVALUATED_TOKEN.position.column !== currentToken.position.column || | ||
| LAST_EVALUATED_TOKEN.position.lineNumber !== currentToken.position.lineNumber || | ||
| LAST_EVALUATED_TOKEN.value === currentToken.value | ||
| lastEvaluatedToken.position.column !== currentToken.position.column || | ||
| lastEvaluatedToken.position.lineNumber !== currentToken.position.lineNumber || | ||
| lastEvaluatedToken.value === currentToken.value | ||
| ) { | ||
| // not on the same place or nothing changed, cache and wait for the next time | ||
| LAST_EVALUATED_TOKEN = currentToken; | ||
| lastEvaluatedToken = currentToken; | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -935,7 +935,7 @@ export default function({ coreEditor: editor, parser }: { coreEditor: CoreEditor | |
| return; | ||
| } | ||
|
|
||
| LAST_EVALUATED_TOKEN = currentToken; | ||
| lastEvaluatedToken = currentToken; | ||
| editor.execCommand('startAutocomplete'); | ||
| }, | ||
| 100); | ||
|
|
@@ -947,17 +947,7 @@ export default function({ coreEditor: editor, parser }: { coreEditor: CoreEditor | |
| } | ||
| } | ||
|
|
||
| function getCompletions( | ||
| DO_NOT_USE: AceEditor, | ||
| DO_NOT_USE_SESSION: IEditSession, | ||
| pos: { row: number; column: number }, | ||
| prefix: string, | ||
| callback: (...args: any[]) => void | ||
| ) { | ||
| const position: Position = { | ||
| lineNumber: pos.row + 1, | ||
| column: pos.column + 1, | ||
| }; | ||
| function getCompletions(position: Position, prefix: string, callback: (...args: any[]) => void) { | ||
| try { | ||
| const context = getAutoCompleteContext(editor, position); | ||
| if (!context) { | ||
|
|
@@ -1028,39 +1018,12 @@ export default function({ coreEditor: editor, parser }: { coreEditor: CoreEditor | |
|
|
||
| editor.on('changeSelection', editorChangeListener); | ||
|
|
||
| // Hook into Ace | ||
|
|
||
| // disable standard context based autocompletion. | ||
| // @ts-ignore | ||
| ace.define('ace/autocomplete/text_completer', ['require', 'exports', 'module'], function( | ||
| require: any, | ||
| exports: any | ||
| ) { | ||
| exports.getCompletions = function( | ||
| innerEditor: any, | ||
| session: any, | ||
| pos: any, | ||
| prefix: any, | ||
| callback: any | ||
| ) { | ||
| callback(null, []); | ||
| }; | ||
| }); | ||
|
|
||
| const langTools = ace.acequire('ace/ext/language_tools'); | ||
|
|
||
| langTools.setCompleters([ | ||
| { | ||
| identifierRegexps: [ | ||
| /[a-zA-Z_0-9\.\$\-\u00A2-\uFFFF]/, // adds support for dot character | ||
| ], | ||
| getCompletions, | ||
| }, | ||
| ]); | ||
|
|
||
| return { | ||
| getCompletions, | ||
| // TODO: This needs to be cleaned up | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! Exporting a special object for testing indicates some spaghetti code somewhere 😊 |
||
| _test: { | ||
| getCompletions, | ||
| getCompletions: (_editor: any, _editSession: any, pos: any, prefix: any, callback: any) => | ||
| getCompletions(pos, prefix, callback), | ||
| addReplacementInfoToContext, | ||
| addChangeListener: () => editor.on('changeSelection', editorChangeListener), | ||
| removeChangeListener: () => editor.off('changeSelection', editorChangeListener), | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preferably ignore these changes for now, they are mostly whitespace and the spec is hard to read. We should definitely address this at some point but for now they provide really decent coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, Github "Hide whitespace changes" makes this easy to parse 😊