Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/monaco-plugin-ob/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oceanbase-odc/monaco-plugin-ob",
"version": "1.7.0",
"version": "1.7.1",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
35 changes: 35 additions & 0 deletions packages/monaco-plugin-ob/src/mysql/worker/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,41 @@ export default {
schemaName = fromTable.schemaName;
break;
}
}
// 如果内层没找到,向外层 Query 查找
if (!tableName) {
const outerQueries: Query[] = [];
queryMap.forEach((query) => {
if (query === tableContext) return;
const [start, stop] = query.location?.range || [];
if (start != null && stop != null && offset - 1 >= start && offset - 1 <= stop) {
outerQueries.push(query);
}
});
// 按范围从小到大排列(最近的外层优先)
outerQueries.sort((a, b) => {
const aSize = (a?.location?.range?.[1] ?? 0) - (a?.location?.range?.[0] ?? 0);
const bSize = (b?.location?.range?.[1] ?? 0) - (b?.location?.range?.[0] ?? 0);
return aSize - bSize;
});
for (const outerQuery of outerQueries) {
for (let fromTable of outerQuery.fromTables) {
let name;
if (fromTable.alias) {
name = fromTable.alias;
} else if (fromTable.tableName) {
name = [fromTable.schemaName, fromTable.tableName]
.filter(Boolean).join('.');
}
if (name === triggerWord) {
isQuery = !!fromTable.query;
tableName = fromTable.tableName;
schemaName = fromTable.schemaName;
break;
}
}
if (tableName) break;
}
}
if (tableName && !isQuery) {
completions = [
Expand Down
35 changes: 35 additions & 0 deletions packages/monaco-plugin-ob/src/obmysql/worker/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,41 @@ export default {
break;
}
}
// 如果内层没找到,向外层 Query 查找
if (!tableName) {
const outerQueries: Query[] = [];
queryMap.forEach((query) => {
if (query === tableContext) return;
const [start, stop] = query.location?.range || [];
if (start != null && stop != null && offset - 1 >= start && offset - 1 <= stop) {
outerQueries.push(query);
}
});
// 按范围从小到大排列(最近的外层优先)
outerQueries.sort((a, b) => {
const aSize = (a?.location?.range?.[1] ?? 0) - (a?.location?.range?.[0] ?? 0);
const bSize = (b?.location?.range?.[1] ?? 0) - (b?.location?.range?.[0] ?? 0);
return aSize - bSize;
});
for (const outerQuery of outerQueries) {
for (let fromTable of outerQuery.fromTables) {
let name;
if (fromTable.alias) {
name = fromTable.alias;
} else if (fromTable.tableName) {
name = [fromTable.schemaName, fromTable.tableName]
.filter(Boolean).join('.');
}
if (name === triggerWord) {
isQuery = !!fromTable.query;
tableName = fromTable.tableName;
schemaName = fromTable.schemaName;
break;
}
}
if (tableName) break;
}
}
if (tableName && !isQuery) {
completions = [
{
Expand Down
48 changes: 42 additions & 6 deletions packages/monaco-plugin-ob/src/oboracle/worker/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ export default {
statement = sqlDocuments?.statements?.[statementsCount - 1];
}
return {
tables: [],
tableVariables: []
};
tables: [],
tableVariables: []
};

},
getAutoCompletion(text, delimiter, offset): AutoCompletionItems {
const convertMap = {
Expand Down Expand Up @@ -271,7 +271,7 @@ export default {
}
return completions;
} else if (result.alterTableStmt) {
console.log('alterTableStmt',result.alterTableStmt);
console.log('alterTableStmt', result.alterTableStmt);
addKeywords();
completions.push({
type: 'allSchemas'
Expand All @@ -291,7 +291,7 @@ export default {
return completions;
} else if (result.dropStmt) {
addKeywords();
switch(result.dropStmt.type) {
switch (result.dropStmt.type) {
case "table":
case "view": {
completions.push({
Expand Down Expand Up @@ -381,6 +381,42 @@ export default {
break;
}
}
// 如果内层没找到,向外层 Query 查找
if (!tableName) {
const outerQueries: Query[] = [];
queryMap.forEach((query) => {
if (query === tableContext) return;
const [start, stop] = query.location?.range || [];
if (start != null && stop != null && offset - 1 >= start && offset - 1 <= stop) {
outerQueries.push(query);
}
});
// 按范围从小到大排列(最近的外层优先)
outerQueries.sort((a, b) => {
const aSize = (a?.location?.range?.[1] ?? 0) - (a?.location?.range?.[0] ?? 0);
const bSize = (b?.location?.range?.[1] ?? 0) - (b?.location?.range?.[0] ?? 0);
return aSize - bSize;
});
for (const outerQuery of outerQueries) {
for (let fromTable of outerQuery.fromTables) {
let name;
if (fromTable.alias) {
name = fromTable.alias;
} else if (fromTable.tableName) {
name = [fromTable.schemaName, fromTable.tableName]
.filter(Boolean).join('.');
}
if (name === triggerWord) {
isQuery = !!fromTable.query;
tableName = fromTable.tableName;
schemaName = fromTable.schemaName;
break;
}
}
if (tableName) break;
}
}

if (tableName && !isQuery) {
completions = [
{
Expand Down
Loading