Exemplo n.º 1
0
        public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            var preSelection = PreSelection.ToLower();
            var returnValues = new List <ICompletionData>();
            var sources      = new List <Source>();

            foreach (var symbol in Project.Symbols)
            {
                if (symbol.Key.ToLower().Contains(preSelection))
                {
                    var source = new Source {
                        Text = symbol.Value.Text, File = symbol.Value.Source, Line = symbol.Value.Line, Character = symbol.Value.Character
                    };
                    if (sources.Contains(source))
                    {
                        continue;
                    }
                    returnValues.Add(new NavigationData(symbol.Value, Project, Events));
                    sources.Add(source);
                }
            }

            foreach (var file in Project.Files)
            {
                if (file.File.Name.ToLower().Contains(preSelection))
                {
                    returnValues.Add(new NavigationData(file, Events));
                }
            }

            return(returnValues.ToArray());
        }
Exemplo n.º 2
0
        public override ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped)
        {
            var preSelection = PreSelection.ToLower();

            // TODO: Don't parse file in this method, do it async while editing file!!
            var symbols         = new List <string>();
            var importedSymbols = new List <string>();
            var returnValues    = new List <ICompletionData>();

            using (var reader = new StringReader(textArea.Document.TextContent))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var importMatch = AsmProjectFile.ImportSymbolRegex.Match(line);
                    if (importMatch.Success)
                    {
                        importedSymbols.AddRange(importMatch.Groups[1].Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(symbol => symbol.Trim()));
                        continue;
                    }

                    var defineMatch = AsmProjectFile.DefineSymbolRegex.Match(line);
                    if (!defineMatch.Success)
                    {
                        defineMatch = AsmProjectFile.DefineProcSymbolRegex.Match(line);
                    }
                    if (defineMatch.Success)
                    {
                        symbols.Add(defineMatch.Groups[1].Value);
                    }
                }
            }

            foreach (var globalSymbol in GlobalSymbols)
            {
                if (!globalSymbol.Value.Text.ToLower().Contains(preSelection))
                {
                    continue;
                }

                /*if (symbols.Contains(globalSymbol.Key) && globalSymbol.Value.Source == fileName)
                 * {
                 *      // TODO: This shouldn't be necessary when we're parsing include-files. Remove commenting if symbols are missing anywhere, but watch out for symbols appearing as duplicates
                 *      returnValues.Add(new Ca65SymbolData(globalSymbol.Value, 1, _getSymbolDescription));
                 * }
                 * else*/if (globalSymbol.Value.Public || (importedSymbols.Contains(globalSymbol.Key) && globalSymbol.Value.Source != fileName))
                {
                    returnValues.Add(new Ca65SymbolData(globalSymbol.Value, 2, _getSymbolDescription));
                }
                else if (!globalSymbol.Value.Public && globalSymbol.Value.LocalToFile == fileName)
                {
                    returnValues.Add(new Ca65SymbolData(globalSymbol.Value, 2, _getSymbolDescription));
                }
            }

            foreach (var opcode in OpcodeParser.GetOpcodes(_project.Type).Values)
            {
                if (!opcode.Command.StartsWith(preSelection, true, CultureInfo.InvariantCulture))
                {
                    continue;
                }
                returnValues.Add(new OpcodeData(opcode)
                {
                    Focus = () => _events.HighlightOpcode(opcode)
                });
            }

            if (PreSelection.StartsWith("."))
            {
                var commands = Ca65Parser.GetCommands();
                foreach (var command in commands.Keys.OrderBy(k => k))
                {
                    if (!command.StartsWith(preSelection, true, CultureInfo.InvariantCulture))
                    {
                        continue;
                    }
                    returnValues.Add(new CommandData(commands[command], command.ToLower())
                    {
                        Focus = () => _events.HighlightCommand(commands[command])
                    });
                }
            }

            //CompletionData = returnValues.OrderBy(d => !d.Text.StartsWith(PreSelection)).ToArray();
            CompletionData = returnValues.ToArray();
            return(CompletionData);
        }