1
0
mirror of https://github.com/salexdv/bsl_console.git synced 2024-11-28 08:48:48 +02:00

Рефакторинг provideQueryDefinition

This commit is contained in:
salexdv 2023-04-10 14:09:04 +03:00
parent e4ee921f18
commit 702ab1c092

View File

@ -7910,6 +7910,85 @@ class bslHelper {
}
/**
* Provide the definition for query field
*
* @returns {array} Location[]
*/
getQueryFieldDefinition() {
let location = null;
let pattern = '(as|как)\\s*' + this.word;
let position = new monaco.Position(this.lineNumber, 1);
let match = Finder.findPreviousMatch(this.model, pattern, position, false);
if (match && match.range.startLineNumber < this.lineNumber) {
let match_position = new monaco.Position(match.range.startLineNumber, match.range.startColumn);
let match_comma = Finder.findPreviousMatch(this.model, ',', match_position, false);
if (match_comma) {
match.range.startLineNumber = match_comma.range.startLineNumber + 1;
match.range.startColumn;
}
location = [{
uri: this.model.uri,
range: match.range
}];
}
return location;
}
/**
* Provide the definition for query source
*
* @returns {array} Location[]
*/
getQuerySourceDefinition() {
let location = null;
let pattern = '(as|как)\\s*' + this.word;
let position = new monaco.Position(this.lineNumber, this.model.getLineMaxColumn(this.lineNumber));
let match = Finder.findNextMatch(this.model, pattern, position, false);
if (match && match.range.startLineNumber > this.lineNumber) {
location = [{
uri: this.model.uri,
range: match.range
}];
}
return location;
}
/**
* Provide the definition for temp table
*
* @returns {array} Location[]
*/
getQueryTempTableDefinition() {
let location = null;
let pattern = '(поместить|into)[\\s\\n\\t]*' + this.word;
let position = new monaco.Position(this.lineNumber, 1);
let match = Finder.findPreviousMatch(this.model, pattern, position, false);
if (match && match.range.startLineNumber < this.lineNumber) {
location = [{
uri: this.model.uri,
range: match.range
}];
}
return location;
}
/**
* Provide the definition of the symbol at the given position of query
*
@ -7921,48 +8000,12 @@ class bslHelper {
if (this.word) {
if (this.wordHasCharsBefore('.')) {
let pattern = '(as|как)\\s*' + this.word;
let position = new monaco.Position(this.lineNumber, 1);
let match = Finder.findPreviousMatch(this.model, pattern, position, false);
if (match && match.range.startLineNumber < this.lineNumber) {
location = [{
uri: this.model.uri,
range: match.range
}];
}
}
else if (this.wordHasCharsAfter('.')) {
let pattern = '(as|как)\\s*' + this.word;
let position = new monaco.Position(this.lineNumber, this.model.getLineMaxColumn(this.lineNumber));
let match = Finder.findNextMatch(this.model, pattern, position, false);
if (match && match.range.startLineNumber > this.lineNumber) {
location = [{
uri: this.model.uri,
range: match.range
}];
}
}
else {
let pattern = '(поместить|into)[\\s\\n\\t]*' + this.word;
let position = new monaco.Position(this.lineNumber, 1);
let match = Finder.findPreviousMatch(this.model, pattern, position, false);
if (match && match.range.startLineNumber < this.lineNumber) {
location = [{
uri: this.model.uri,
range: match.range
}];
}
}
if (this.wordHasCharsBefore('.'))
location = this.getQueryFieldDefinition()
else if (this.wordHasCharsAfter('.'))
location = this.getQuerySourceDefinition();
else
location = this.getQueryTempTableDefinition();
}