restore file

pull/5370/head
filip mertens 2 years ago
parent b492a0eef8
commit 03ccce7582
  1. 86
      libs/remix-ui/editor/src/lib/providers/completionProvider.ts

@ -3,7 +3,7 @@ import { isArray } from "lodash"
import { editor, languages, Position } from "monaco-editor" import { editor, languages, Position } from "monaco-editor"
import monaco from "../../types/monaco" import monaco from "../../types/monaco"
import { EditorUIProps } from "../remix-ui-editor" import { EditorUIProps } from "../remix-ui-editor"
import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetGlobalFunctions, GetGlobalVariable, GetImports } from "./completion/completionGlobals" import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetGlobalFunctions, GetGlobalVariable } from "./completion/completionGlobals"
export class RemixCompletionProvider implements languages.CompletionItemProvider { export class RemixCompletionProvider implements languages.CompletionItemProvider {
@ -16,15 +16,12 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
this.monaco = monaco this.monaco = monaco
} }
triggerCharacters = ['.', '', '"', '@', '/'] triggerCharacters = ['.', '']
async provideCompletionItems(model: editor.ITextModel, position: Position, context: monaco.languages.CompletionContext): Promise<monaco.languages.CompletionList | undefined> { async provideCompletionItems(model: editor.ITextModel, position: Position, context: monaco.languages.CompletionContext): Promise<monaco.languages.CompletionList | undefined> {
const completionSettings = await this.props.plugin.call('config', 'getAppParameter', 'settings/auto-completion') const completionSettings = await this.props.plugin.call('config', 'getAppParameter', 'settings/auto-completion')
if (!completionSettings) return if (!completionSettings) return
<<<<<<< HEAD
=======
>>>>>>> a82c40d86150cabc4d774c312ed442613d04e8bc
const word = model.getWordUntilPosition(position); const word = model.getWordUntilPosition(position);
const range = { const range = {
startLineNumber: position.lineNumber, startLineNumber: position.lineNumber,
@ -37,103 +34,32 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
let nodes: AstNode[] = [] let nodes: AstNode[] = []
let suggestions: monaco.languages.CompletionItem[] = [] let suggestions: monaco.languages.CompletionItem[] = []
if (context.triggerCharacter === '"' || context.triggerCharacter === '@' || context.triggerCharacter === '/') {
<<<<<<< HEAD
// handles completion from for builtin types
if (lastNodeInExpression.memberName === 'sender') { // exception for this member
lastNodeInExpression.name = 'sender'
}
const globalCompletion = getContextualAutoCompleteByGlobalVariable(lastNodeInExpression.name, range, this.monaco)
if (globalCompletion) {
dotCompleted = true
suggestions = [...suggestions, ...globalCompletion]
}
// handle completion for global THIS.
if (lastNodeInExpression.name === 'this') {
dotCompleted = true
nodes = [...nodes, ...await this.getThisCompletions()]
}
// handle completion for other dot completions
if (expressionElements.length > 1 && !dotCompleted) {
const nameOfLastTypedExpression = lastNodeInExpression.name || lastNodeInExpression.memberName
const dotCompletions = await this.getDotCompletions(nameOfLastTypedExpression, range)
nodes = [...nodes, ...dotCompletions.nodes]
suggestions = [...suggestions, ...dotCompletions.suggestions]
=======
const lastpart = line.substring(0, position.column - 1).split(';').pop()
if (lastpart.startsWith('import')) {
const imports = await this.props.plugin.call('codeParser', 'getImports')
if (context.triggerCharacter === '"' || context.triggerCharacter === '@') {
suggestions = [...suggestions,
...GetImports(range, this.monaco, imports, context.triggerCharacter),
]
} else if (context.triggerCharacter === '/') {
const word = line.split('"')[1]
suggestions = [...suggestions,
...GetImports(range, this.monaco, imports, word),
]
} else {
return
}
>>>>>>> a82c40d86150cabc4d774c312ed442613d04e8bc
}
} else
<<<<<<< HEAD
// handles contract completions and other suggestions
suggestions = [...suggestions,
...GetGlobalVariable(range, this.monaco),
...getCompletionSnippets(range, this.monaco),
...GetCompletionTypes(range, this.monaco),
...GetCompletionKeywords(range, this.monaco),
...GetGlobalFunctions(range, this.monaco),
...GeCompletionUnits(range, this.monaco),
]
let contractCompletions = await this.getContractCompletions()
=======
if (context.triggerCharacter === '.') { if (context.triggerCharacter === '.') {
const lineTextBeforeCursor: string = line.substring(0, position.column - 1) const lineTextBeforeCursor: string = line.substring(0, position.column - 1)
const lastNodeInExpression = await this.getLastNodeInExpression(lineTextBeforeCursor) const lastNodeInExpression = await this.getLastNodeInExpression(lineTextBeforeCursor)
const expressionElements = lineTextBeforeCursor.split('.') const expressionElements = lineTextBeforeCursor.split('.')
let dotCompleted = false let dotCompleted = false
>>>>>>> a82c40d86150cabc4d774c312ed442613d04e8bc
// handles completion from for builtin types // handles completion from for builtin types
if (lastNodeInExpression.memberName === 'sender') { // exception for this member if (lastNodeInExpression.memberName === 'sender') { // exception for this member
lastNodeInExpression.name = 'sender' lastNodeInExpression.name = 'sender'
} }
<<<<<<< HEAD
return true
})
nodes = [...nodes, ...contractCompletions]
=======
const globalCompletion = getContextualAutoCompleteByGlobalVariable(lastNodeInExpression.name, range, this.monaco) const globalCompletion = getContextualAutoCompleteByGlobalVariable(lastNodeInExpression.name, range, this.monaco)
if (globalCompletion) { if (globalCompletion) {
dotCompleted = true dotCompleted = true
suggestions = [...suggestions, ...globalCompletion] suggestions = [...suggestions, ...globalCompletion]
setTimeout(() => {
// eslint-disable-next-line no-debugger
// debugger
}, 2000)
} }
// handle completion for global THIS. // handle completion for global THIS.
if (lastNodeInExpression.name === 'this') { if (lastNodeInExpression.name === 'this') {
dotCompleted = true dotCompleted = true
nodes = [...nodes, ...await this.getThisCompletions(position)] nodes = [...nodes, ...await this.getThisCompletions()]
} }
// handle completion for other dot completions // handle completion for other dot completions
if (expressionElements.length > 1 && !dotCompleted) { if (expressionElements.length > 1 && !dotCompleted) {
>>>>>>> a82c40d86150cabc4d774c312ed442613d04e8bc
const nameOfLastTypedExpression = lastNodeInExpression.name || lastNodeInExpression.memberName const nameOfLastTypedExpression = lastNodeInExpression.name || lastNodeInExpression.memberName
const dotCompletions = await this.getDotCompletions(position, nameOfLastTypedExpression, range) const dotCompletions = await this.getDotCompletions(nameOfLastTypedExpression, range)
nodes = [...nodes, ...dotCompletions.nodes] nodes = [...nodes, ...dotCompletions.nodes]
suggestions = [...suggestions, ...dotCompletions.suggestions] suggestions = [...suggestions, ...dotCompletions.suggestions]
} }
@ -148,7 +74,8 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
...GetGlobalFunctions(range, this.monaco), ...GetGlobalFunctions(range, this.monaco),
...GeCompletionUnits(range, this.monaco), ...GeCompletionUnits(range, this.monaco),
] ]
let contractCompletions = await this.getContractCompletions(position)
let contractCompletions = await this.getContractCompletions()
// we can't have external nodes without using this. // we can't have external nodes without using this.
contractCompletions = contractCompletions.filter(node => { contractCompletions = contractCompletions.filter(node => {
@ -157,6 +84,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
} }
return true return true
}) })
nodes = [...nodes, ...contractCompletions] nodes = [...nodes, ...contractCompletions]
} }

Loading…
Cancel
Save