|
1 | | -import _ from 'lodash'; |
2 | | -import globalcache from '@js/service/db/globalcache.js'; |
| 1 | +import { map, isEmpty } from 'lodash'; |
| 2 | +import util from '../util'; |
3 | 3 | import storage from '@/js/helper/storage'; |
4 | 4 |
|
5 | 5 | const pyKeywordInfoProposals = [ |
@@ -215,69 +215,55 @@ const pyKeywordInfoProposals = [ |
215 | 215 | }, |
216 | 216 | ]; |
217 | 217 |
|
218 | | -/** |
219 | | - * 对拿到的数据格式化成completionList格式 |
220 | | - * @param {*} monaco 编辑器 |
221 | | - * @param {*} list 格式化列表 |
222 | | - * @return {*} 格式化后的列表 |
223 | | - */ |
224 | | -function completionListFormatter(monaco, list) { |
225 | | - const formatList = []; |
226 | | - list.forEach((item) => { |
227 | | - if (item.udfType === 1 || item.udfType === 3) { |
228 | | - formatList.push({ |
229 | | - label: item.udfName, |
230 | | - kind: monaco.languages.CompletionItemKind.Function, |
231 | | - insertText: item.udfName, |
232 | | - detail: item.udfType > 2 ? '方法函数' : 'UDF函数', |
233 | | - documentation: item.description, |
234 | | - }); |
235 | | - } |
236 | | - }); |
237 | | - return formatList; |
238 | | -} |
| 218 | +let functionProposals = []; |
239 | 219 |
|
240 | 220 | export default { |
241 | 221 | async register(monaco) { |
242 | | - const userInfo = storage.get('userInfo'); |
243 | | - const userName = userInfo.basic.userName; |
244 | | - const globalCache = await globalcache.getCache(userName); |
| 222 | + const lang = 'python'; |
245 | 223 |
|
246 | | - const pyProposals = _.map(pyKeywordInfoProposals, (item) => ({ |
| 224 | + const pyProposals = map(pyKeywordInfoProposals, (item) => ({ |
247 | 225 | label: item.label.toLowerCase(), |
248 | 226 | kind: monaco.languages.CompletionItemKind.Keyword, |
249 | 227 | insertText: item.insertText.toLowerCase(), |
250 | 228 | detail: item.detail, |
251 | 229 | documentation: item.documentation, |
252 | 230 | })); |
253 | 231 |
|
254 | | - let functionProposals = completionListFormatter(monaco, globalCache.fnList); |
| 232 | + util.getHiveList(monaco, lang).then((list) => { |
| 233 | + functionProposals = list.udfProposals; |
| 234 | + }); |
255 | 235 |
|
256 | 236 | monaco.languages.registerCompletionItemProvider('python', { |
257 | 237 | triggerCharacters: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._'.split(''), |
258 | 238 | async provideCompletionItems(model, position) { |
| 239 | + if (isEmpty(functionProposals)) { |
| 240 | + util.getHiveList(monaco, lang).then((list) => { |
| 241 | + functionProposals = list.udfProposals; |
| 242 | + }); |
| 243 | + } |
| 244 | + |
259 | 245 | const textUntilPosition = model.getValueInRange({ |
260 | 246 | startLineNumber: position.lineNumber, |
261 | 247 | startColumn: 1, |
262 | 248 | endLineNumber: position.lineNumber, |
263 | 249 | endColumn: position.column, |
264 | 250 | }); |
265 | | - let completionList = null; |
266 | 251 | const keywordMatch = textUntilPosition.match(/([^"]*)?$/i); |
267 | 252 | const functionMatch = textUntilPosition.match(/\s+/i); |
268 | 253 | if (functionMatch) { |
269 | 254 | const isFunctionChange = storage.get('isFunctionChange_python'); |
270 | 255 | // 如果函数发生load状态变化,则重新从indexdb中获取fnlist |
271 | 256 | if (isFunctionChange) { |
272 | 257 | storage.set('isFunctionChange_python', false); |
273 | | - const globalCache = await globalcache.getCache(userName); |
274 | | - functionProposals = completionListFormatter(monaco, globalCache.fnList); |
| 258 | + await util.getHiveList(monaco, lang).then((list) => { |
| 259 | + return list.udfProposals; |
| 260 | + }); |
275 | 261 | } |
276 | | - completionList = functionProposals; |
| 262 | + return functionProposals; |
277 | 263 | } else if (keywordMatch) { |
278 | | - completionList = pyProposals; |
| 264 | + return pyProposals; |
279 | 265 | } |
280 | | - return completionList; |
| 266 | + return []; |
281 | 267 | }, |
282 | 268 | }); |
283 | 269 | }, |
|
0 commit comments