Beispiel #1
0
        /// <summary>
        /// Vrati autokompletion pre include,
        /// </summary>
        /// <returns>
        /// Zoznam autoCompletion slov pre include
        /// </returns>
        public static ICompletionDataList GetCompletionData(this TextEditor editor ,string baseWord,string fullWord)
        {
            /*
                lib - ms a adresare z framevorku
                app - ms adresare z projektu

             */
            List<string> libsDefine = new List<string>();
            GetAllFiles(ref libsDefine,MainClass.Settings.LibDirectory);
            //GetAllFiles(ref libsDefine,MainClass.Workspace.ActualProject.AbsolutProjectDir);

            CompletionDataList listComplete = new CompletionDataList();
            foreach (string str in libsDefine){
                CompletionData cd = new CompletionData(str,null,"","\""+str+"\"");
                listComplete.Add(cd);
            }

            //listComplete.AddRange(MainClass.CompletedCache.IncludeCompletion);
            return listComplete;
        }
Beispiel #2
0
        public void GetCompletedData()
        {
            ListDataKeywords=new List<CompletionData>();
            ListDataTypes =new List<CompletionData>();
            ListDataMembers =new List<CompletionData>();
            ListDataProperties =new List<CompletionData>();
            ListDataEvents =new List<CompletionData>();

            AllCompletionRepeat=new CompletionDataList();
            AllCompletionOnlyOne =new CompletionDataList();
            NewCompletion =new CompletionDataList();
            DotCompletion =new CompletionDataList();

            if(!System.IO.File.Exists(FilePath)){
                Tool.Logger.Error("CodeCompletion file not exist!",null);
                return;
            }

            SqlLiteDal sqlLiteDal = new SqlLiteDal(FilePath);

            SqliteConnection dbcon =  (SqliteConnection)sqlLiteDal.GetConnect();//GetConnect();
            if (dbcon == null){
                return;
            }

            SqliteCommand dbcmd = dbcon.CreateCommand();

            string sql = "SELECT *  FROM completed;";
            dbcmd.CommandText = sql;
            SqliteDataReader reader = null;
            try {
                reader = dbcmd.ExecuteReader();

                int numberCollumns = reader.FieldCount;

                if (numberCollumns <5)return;

                while (reader.Read()) {

                    CompletionData cd;
                    string name = reader.GetValue(1).ToString();
                    string signature= reader.GetValue(2).ToString();
                    int type=  reader.GetInt32(3);
                    string parent= reader.GetValue(4).ToString();
                    string summary = "";
                    string returnType = "";
                    if(numberCollumns >=6)
                        summary= reader.GetValue(5).ToString();

                    if(numberCollumns >=7)
                        returnType= reader.GetValue(6).ToString();

                    cd = new CompletionData(name,null,signature,name,1,parent,returnType);

                    cd.Signature =signature;

                    if(!string.IsNullOrEmpty(summary)){
                        cd.Description = cd.Description + Environment.NewLine+ summary;//+Environment.NewLine;
                    }

                    if(type == (int)CompletionDataTyp.keywords){
                        ListDataKeywords.Add(cd);
                    } else if(type == (int)CompletionDataTyp.members){
                        ListDataMembers.Add(cd);
                    } else if(type == (int)CompletionDataTyp.types){
                        ListDataTypes.Add(cd);
                    } else if(type == (int)CompletionDataTyp.properties){
                        ListDataProperties.Add(cd);
                    } else if(type == (int)CompletionDataTyp.events){
                        ListDataEvents.Add(cd);
                    }
                }

            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                Tool.Logger.Error("ERROR LOADING COMPLETED CACHE");
                Tool.Logger.Error(ex.Message);

                //MessageDialogs ms = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "Error", ex.Message, MessageType.Error);
                //ms.ShowDialog();

            } finally {

                if (reader != null) reader.Close();
                reader = null;
                dbcmd.Dispose();
                dbcmd = null;
                dbcon.Close();
                dbcon = null;
            }
            AllCompletionRepeat=GetCompletionData(CompletionTyp.allType,false );
            AllCompletionOnlyOne =GetCompletionData(CompletionTyp.allType,true );
            NewCompletion =GetCompletionData(CompletionTyp.newType,true );
            DotCompletion =GetCompletionData(CompletionTyp.dotType,true );
            IncludeCompletion =GetCompletionData(CompletionTyp.includeType,true );
        }
Beispiel #3
0
        /// <summary>
        /// Vrati vsetky mozne autokompletion , do zoznamu prida aj slova zo samotneho dokumentu
        /// </summary>
        /// <returns>
        /// Zoznam autoCompletion slov odpovesajuci baseWord a completiontype
        /// </returns>
        public static ICompletionDataList GetCompletionData(this TextEditor editor ,string baseWord,string fullWord ,CompletionTyp completiontype)
        {
            string codestring = editor.Document.Text;
            string type = "";
            string parent = "";

            editor.ParseString(fullWord,out parent,out type);

            Regex regex = new Regex(@"\W", RegexOptions.Compiled);
            codestring = regex.Replace(codestring, " ");

            string[] list = codestring.Split(' ');
            CompletionDataList listComplete = new CompletionDataList();
            listComplete.CompletionSelectionMode = CompletionSelectionMode.OwnTextField;

            if(!String.IsNullOrEmpty(type)){
                //List<CompletionData> lst = MainClass.CompletedCache.AllCompletionOnlyOne.FindAll(x=>x.Parent == type);
                List<CompletionData> lst = MainClass.CompletedCache.AllCompletionRepeat.FindAll(x=>x.Parent == type);
                foreach ( CompletionData cd in lst){
                    string expres =cd.Parent+".on";
                    if(cd.Signature.StartsWith(expres) ){
                        //expres = cd.Signature.Replace(cd.Parent+".", cd.DisplayText +" = function ");
                        expres = cd.Signature.Replace(cd.Parent+"."+ cd.DisplayText, cd.DisplayText +" = function ");
                        cd.DisplayDescription =expres+"{}";
                        cd.CompletionText =expres+"{"+Environment.NewLine+"}";
                    }

                }

                if (lst != null)
                    listComplete.AddRange(lst.ToArray());

                if(listComplete != null && listComplete.Count>0){
                    return listComplete;
                }
            }

            switch (completiontype) {
            case CompletionTyp.allType:
                {
                    listComplete.AddRange(MainClass.CompletedCache.AllCompletionOnlyOne);
                    break;
                }
            case CompletionTyp.newType:
                {
                    listComplete.AddRange(MainClass.CompletedCache.NewCompletion);
                    break;
                }
            case CompletionTyp.dotType:
                {
                    listComplete.AddRange(MainClass.CompletedCache.DotCompletion);
                    break;
                }
            }

            int i = 0;
            foreach (string s in list) {
                if ( !String.IsNullOrEmpty(s.Trim()) ){
                    if (s==baseWord)
                        i++;

                    if ((listComplete.Find(s)== null) && (s.Length>2) && ( (s!= baseWord) || (i ==1) ) ){
                        CompletionData cd = new CompletionData(s, null, s, s);

                        if (completiontype == CompletionTyp.newType){
                            if(char.ToUpper(s[0]) == s[0]  && !char.IsDigit(s[0]) && !char.IsSymbol(s[0]) &&char.IsLetter(s[0]) ){

                                CompletionData cdParent =listComplete.Find(cd.DisplayText);
                                if (cdParent== null){
                                    listComplete.Add(cd);
                                } else {
                                    if(!cdParent.Description.Contains(cd.Description))
                                        cdParent.Description =cdParent.Description+Environment.NewLine+cd.Description;
                                }
                            }
                        }  else{
                            CompletionData cdParent =listComplete.Find(cd.DisplayText);
                            if (cdParent== null){
                                listComplete.Add(cd);
                            } else {
                                if(!cdParent.Description.Contains(cd.Description))
                                    cdParent.Description =cdParent.Description+Environment.NewLine+cd.Description;
                            }
                        }
                    }
                }
            }

             			return listComplete;
        }