Beispiel #1
0
        //public override IScanner GetScanner(Microsoft.VisualStudio.Text.ITextBuffer buffer) {

        //public override CodeWindowManager CreateCodeWindowManager(IVsCodeWindow codewindow, Source source) {
        //    NSCodeWindow nscw = new NSCodeWindow(codewindow, source);
        //    return nscw;
        //}

        public override void OnCloseSource(Source source)
        {
            string codefile_path = source.GetFilePath();

            if (filelist.ContainsKey(codefile_path))
            {
                string dirty_file = filelist[codefile_path];
                filelist.Remove(codefile_path);
                if (File.Exists(dirty_file))
                {
                    try {
                        File.Delete(dirty_file);
                    } catch (Exception ex) {
                        NSUtil.DebugPrintAlways("Error deleting temp file:" + ex.Message);
                    }
                }
                NimBaseFileCreate();
            }
            base.OnCloseSource(source);
            return;
            //CodeWindowManager cwm = GetCodeWindowManagerForSource(source);
            //if (cwm != null) {
            //    IVsTextView tv;
            //    cwm.CodeWindow.GetLastActiveView(out tv);
            //    if (tv != null)
            //        tv.CloseView();
            //}
            //source.Close();
            //base.OnCloseSource(source);
        }
Beispiel #2
0
        public override ParseRequest BeginParse(int line, int idx, TokenInfo info, ParseReason reason, IVsTextView view, ParseResultHandler callback)
        {
            //return base.BeginParse(line, idx, info, reason, view, callback);

            switch (reason)
            {
            case ParseReason.Autos:
                break;

            case ParseReason.Check:
                m_parse_reason = ParseReason.Check;
                NSUtil.DebugPrintAlways("NSSource BeginParse Check");
                //m_scanner.m_fullscan = 3;
                //Recolorize(0,LineCount);
                //m_scanner.m_fullscan = false;
                //Recolorize(0, this.LineCount);
                break;

            //return null;
            case ParseReason.CodeSpan:
                break;

            case ParseReason.CompleteWord:
                break;

            case ParseReason.DisplayMemberList:
                break;

            case ParseReason.Goto:
                break;

            case ParseReason.MemberSelect:
                break;

            case ParseReason.MemberSelectAndHighlightBraces:
                break;

            case ParseReason.MethodTip:
                break;

            case ParseReason.None:
                break;

            case ParseReason.QuickInfo:
                break;

            case ParseReason.HighlightBraces:
            case ParseReason.MatchBraces:
                Trace.Assert(false);
                break;

            default:
                break;
            }

            return(base.BeginParse(line, idx, info, reason, view, callback));
            //return null;
        }
Beispiel #3
0
 public override void OnActiveViewChanged(IVsTextView textview)
 {
     // also called for new textviews
     NSUtil.DebugPrintAlways("OnActiveViewChanged");
     if (textview != null)
     {
         textview_current = textview;
         var source = GetSource(textview);
         codefile_path_current = source.GetFilePath();
         NSUtil.DebugPrintAlways("OnActiveViewChanged:" + codefile_path_current);
         if (!filelist.ContainsKey(codefile_path_current))
         {
             //string fstr = Path.GetFileNameWithoutExtension(codefile_path_current);
             string fdirtystr = Path.GetTempFileName();
             filelist.Add(codefile_path_current, fdirtystr);
             NimBaseFileCreate();
         }
         base.OnActiveViewChanged(textview);
     }
 }
Beispiel #4
0
        /// <summary>Queries nimsuggest</summary><param name='qtype'>use qtype class constants</param><param name='qline'>code line number</param><param name='qcol'>code column number</param>
        public void Query(string qtype, object qline, object qcol)
        {
            Microsoft.VisualStudio.TextManager.Interop.IVsTextLines lines;
            NSLangServ.textview_current.GetBuffer(out lines);
            int numlines, column;

            lines.GetLineCount(out numlines);
            lines.GetLengthOfLine(numlines - 1, out column);
            String strbuff;

            NSLangServ.textview_current.GetTextStream(0, 0, numlines - 1, column, out strbuff);
            File.WriteAllText(NSLangServ.filelist[NSLangServ.codefile_path_current], strbuff, new UTF8Encoding(false));

            //string fstr = Path.GetFileNameWithoutExtension(NSLangServ.codefile_path_current);

            if (NSPackage.quickinfo || NSPackage.memberlist)
            {
                NSPackage.quickinfo  = false;
                NSPackage.memberlist = false;
                //NSUtil.SaveIfDirty(NSLangServ.codefile_path_current);
            }

            //if (fstr != filepath_prev) {
            //    Close();
            //    Init();
            //}
            //if (!NSLangServ.filelist.ContainsKey(NSLangServ.codefile_path_current)) {


            //    // create or update nimstudio_base.nim, which contains: import openfile1, openfile2, ..
            //    // nimstudio_base.nim is the initial file passed to nimsuggest
            //    filelist.Add(fstr);
            //    string basefile = "import " + string.Join(",", filelist);
            //    StreamWriter sw1 = new StreamWriter(Path.GetDirectoryName(NSLangServ.codefile_path_current) + @"\nimstudio_base.nim");
            //    sw1.WriteLine(basefile);
            //    sw1.Close();
            //}

            //if (!filelist.Contains(fstr)) {
            //    // create or update nimstudio_base.nim, which contains: import openfile1, openfile2, ..
            //    // nimstudio_base.nim is the initial file passed to nimsuggest
            //    filelist.Add(fstr);
            //    string basefile = "import " + string.Join(",", filelist);
            //    StreamWriter sw1 = new StreamWriter(Path.GetDirectoryName(NSLangServ.codefile_path_current) + @"\nimstudio_base.nim");
            //    sw1.WriteLine(basefile);
            //    sw1.Close();
            //}

            if (proc == null)
            {
                Init();
            }
            if (proc == null)
            {
                return;
            }

            conout.Clear();
            sugdct.Clear();
            queryfinished = false;
            //string qstr = qtype + " " + fstr + ".nim:" + qline.ToString() + ":" + qcol.ToString();
            string qstr =
                String.Format(@"{0} ""{1}"";""{2}"":{3}:{4}",
                              qtype,                                                 // 0
                              NSLangServ.codefile_path_current,                      // 1
                              NSLangServ.filelist[NSLangServ.codefile_path_current], // 2
                              qline,                                                 // 3
                              qcol                                                   // 4
                              );

            // + NSLangServ.codefile_path_current + ".nim\";" +
            //    NSLangServ.filelist[NSLangServ.codefile_path_current]
            //":" + qline.ToString() + ":" + qcol.ToString();

            //string qstr = qtype + " \"" + NSLangServ.codefile_path_current + ".nim\";" +
            //    NSLangServ.filelist[NSLangServ.codefile_path_current]
            // ":" + qline.ToString() + ":" + qcol.ToString();


            NSUtil.DebugPrintAlways("NimStudio - query:" + qstr);
            proc.StandardInput.WriteLine(qstr);
            int waitcount = 0;

            while (!queryfinished)
            {
                Thread.Sleep(25);
                waitcount++;
                if (waitcount > 200)
                {
                    // 5 second wait cap
                    //VSNimUtil.DebugPrint("NimStudio - querywait max hit");
                    con.Write("NimStudio - querywait max hit");
                    queryfinished = true;
                    break;
                }
            }
            string fnamestrip = Path.GetFileNameWithoutExtension(NSLangServ.codefile_path_current) + ".";

            NSUtil.DebugPrint("NimStudio - conout.count:" + conout.Count.ToString());
            foreach (string cstr in conout)
            {
                if (cstr == null)
                {
                    continue;
                }
                NSUtil.DebugPrint("NimStudio - conout:" + cstr);
                string[] sugsplit = cstr.Split(new char[] { '\t' });
                if (sugsplit.Length < 2)
                {
                    continue;
                }
                if (sugsplit[Sugspl.kind] == "skProc" || sugsplit[Sugspl.kind] == "skVar")
                {
                    if (qtype == Qtype.def)
                    {
                        if (sugsplit[Sugspl.kind] == "skVar")
                        {
                            sugsplit[Sugspl.type] = "(" + sugsplit[Sugspl.type] + ")";
                        }
                        sugsplit[Sugspl.type] = Regex.Replace(sugsplit[Sugspl.type], @"{.*?}", "");
                        sugsplit[Sugspl.name] = sugsplit[Sugspl.name].Replace(fnamestrip, "");
                        sugsplit[Sugspl.help] = sugsplit[Sugspl.help].Replace(@"\x0D\x0A", "\n");
                        sugsplit[Sugspl.help] = sugsplit[Sugspl.help].Trim(new char[] { '"' });
                        if (sugsplit[Sugspl.help] != "")
                        {
                            sugsplit[Sugspl.help] = "\n\n" + sugsplit[Sugspl.help];
                        }
                        sugdct.Add(sugsplit[Sugspl.name], new SortedDictionary <string, string>()
                        {
                            { "kind", sugsplit[Sugspl.kind] }, { "type", sugsplit[Sugspl.type] }, { "help", sugsplit[Sugspl.help] }
                        });
                    }
                    else if (qtype == Qtype.con)
                    {
                        sugsplit[Sugspl.name] = sugsplit[Sugspl.name].Replace(fnamestrip, "");
                        sugsplit[Sugspl.type] = Regex.Replace(sugsplit[Sugspl.type], @"{.*?}", "");
                        sugsplit[Sugspl.help] = sugsplit[Sugspl.help].Replace(@"\x0D\x0A ", "\n");
                        sugsplit[Sugspl.help] = sugsplit[Sugspl.help].Replace(@"\x0D\x0A", "\n");
                        sugsplit[Sugspl.help] = sugsplit[Sugspl.help].Trim(new char[] { '"' });
                        if (sugdct.ContainsKey(sugsplit[Sugspl.type]))
                        {
                            Debug.Print("Error");
                        }
                        else
                        {
                            sugdct.Add(sugsplit[Sugspl.type], new SortedDictionary <string, string>()
                            {
                                { "kind", sugsplit[Sugspl.kind] }, { "name", sugsplit[Sugspl.name] }, { "help", sugsplit[Sugspl.help] }
                            });
                        }
                    }
                    else
                    {
                        sugsplit[Sugspl.name] = sugsplit[Sugspl.name].Replace(fnamestrip, "");
                        sugsplit[Sugspl.type] = Regex.Replace(sugsplit[Sugspl.type], @"{.*?}", "");
                        sugsplit[Sugspl.help] = sugsplit[Sugspl.help].Replace(@"\x0D\x0A", "\n");
                        sugsplit[Sugspl.help] = sugsplit[Sugspl.help].Trim(new char[] { '"' });
                        if (sugsplit[Sugspl.help] != "")
                        {
                            sugsplit[Sugspl.help] = "\n\n" + sugsplit[Sugspl.help];
                        }
                        if (sugdct.ContainsKey(sugsplit[Sugspl.name]))
                        {
                            if (sugsplit[Sugspl.kind] != "skVar" && sugdct[sugsplit[Sugspl.name]]["type"] != sugsplit[Sugspl.type])
                            {
                                // add overload
                                sugdct[sugsplit[Sugspl.name]]["type"] += "\n" + sugsplit[Sugspl.type];
                            }
                        }
                        else
                        {
                            sugdct.Add(sugsplit[Sugspl.name], new SortedDictionary <string, string>()
                            {
                                { "kind", sugsplit[Sugspl.kind] }, { "type", sugsplit[Sugspl.type] }, { "help", sugsplit[Sugspl.help] }
                            });
                        }
                    }
                }
            }
            NSUtil.DebugPrint("NimStudio - suggs count:" + sugdct.Count.ToString());
        }
Beispiel #5
0
        //[CLSCompliantAttribute(false)]
        //public delegate void ParseResultHandler(ParseRequest request);

        public override AuthoringScope ParseSource(ParseRequest req)
        {
            NSSource source = (NSSource)this.GetSource(req.FileName);

            switch (req.Reason)
            {
            case ParseReason.HighlightBraces:
            case ParseReason.MatchBraces:
                break;

            case ParseReason.Check:
                NSUtil.DebugPrintAlways("AuthoringScope ParseSource Check");
                source.m_scanner.FullScan();
                source.Recolorize(0, source.LineCount);

                //source.m_scanner.m_fullscan = true;
                //source.Recolorize(0,source.LineCount);
                //source.m_scanner.m_fullscan = false;
                //NSUtil.DebugPrintAlways("AuthoringScope ParseSource END");
                break;

            case ParseReason.QuickInfo:

                //IVsTextLines buffer = null;
                //buffer = source.GetTextLines();
                //int totlines;
                //buffer.GetLineCount(out totlines);
                //LINEDATA[] ld;
                ////buffer.GetLineData(1,ld,null);
                //int linelen;
                //buffer.GetLengthOfLine(7,out linelen);
                //TextSpan hideSpan = new TextSpan();
                //hideSpan.iStartIndex = 1;
                //hideSpan.iStartLine = 10;
                //hideSpan.iEndIndex = linelen;
                //hideSpan.iEndLine = 13;
                //req.Sink.ProcessHiddenRegions = true;
                //req.Sink.AddHiddenRegion(hideSpan, "THIS");

                break;

            case ParseReason.MemberSelectAndHighlightBraces:
                //if (source.Braces != null) {
                //    foreach (TextSpan[] brace in source.GetTextLines()) {
                //        if (brace.Length == 2) {
                //            if (req.Sink.HiddenRegions == true
                //                  && source.GetText(brace[0]).Equals("{")
                //                  && source.GetText(brace[1]).Equals("}")) {
                //                //construct a TextSpan of everything between the braces
                //                TextSpan hideSpan = new TextSpan();
                //                hideSpan.iStartIndex = brace[0].iStartIndex;
                //                hideSpan.iStartLine = brace[0].iStartLine;
                //                hideSpan.iEndIndex = brace[1].iEndIndex;
                //                hideSpan.iEndLine = brace[1].iEndLine;
                //                req.Sink.ProcessHiddenRegions = true;
                //                req.Sink.AddHiddenRegion(hideSpan);
                //            }
                //            req.Sink.MatchPair(brace[0], brace[1], 1);
                //        } else if (brace.Length >= 3)
                //            req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1);
                //    }
                //}
                break;

            default:
                break;
            }
            //return new MyAuthoringScope();

            return(new NSAuthoringScope(req, req.FileName, ""));
            //return req.Scope;
        }
Beispiel #6
0
 public ISignature GetBestMatch(ISignatureHelpSession session)
 {
     NSUtil.DebugPrintAlways("NSSig - GetBestMatch");
     return(session.Signatures.Count > 0 ? session.Signatures[0] : null);
 }
Beispiel #7
0
        public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures)
        {
            //if (!session.TextView.Properties.ContainsProperty(SessionKey)) {
            //    return;
            //}
            NSUtil.DebugPrintAlways("NSSig - AugmentSignatureHelpSession");

            if (NSPackage.nimsuggest == null)
            {
                return;
            }

            signatures.Clear();
            var caretpos = NSLangServ.CaretPosGet();

            NSPackage.nimsuggest.Query(NimSuggestProc.Qtype.con, caretpos["line"], caretpos["col"]);

            SnapshotPoint?point_trigger = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot);

            if (!point_trigger.HasValue)
            {
                return;
            }

            //ITextSnapshot snapshot = subjectBuffer.CurrentSnapshot;
            //int position = session.GetTriggerPoint(subjectBuffer).GetPosition(subjectBuffer.CurrentSnapshot);
            int position = point_trigger.Value.Position;

            string text = subjectBuffer.CurrentSnapshot.GetText();

            SnapshotPoint point_curr = session.GetTriggerPoint(subjectBuffer).GetPoint(subjectBuffer.CurrentSnapshot);

            point_curr = point_trigger.Value;
            SnapshotPoint point_left  = point_curr;
            SnapshotPoint point_right = point_curr;

            ITextSnapshotLine line  = point_left.GetContainingLine();
            string            terms = "\n\r\t.:()[]{}?/+-;=*!<>";

            while (true)
            {
                point_left -= 1;
                if (point_left <= line.Start)
                {
                    point_left = line.Start;
                    break;
                }
                if (terms.IndexOf(point_left.GetChar()) != -1)
                {
                    point_left += 1;
                    break;
                }
            }
            while (true)
            {
                if (point_right >= line.End)
                {
                    point_right = line.End;
                    break;
                }
                if (terms.IndexOf(point_right.GetChar()) != -1)
                {
                    point_right -= 1;
                    break;
                }
                point_right += 1;
            }
            if (point_left > point_right)
            {
                point_right = point_left;
            }
            ITrackingSpan applicable_to_span = subjectBuffer.CurrentSnapshot.CreateTrackingSpan(point_left, point_right - point_left, SpanTrackingMode.EdgeInclusive);
            //ITrackingSpan applicableToSpan = subjectBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0);

            string sig_help_default = "";

            foreach (string skey in NSPackage.nimsuggest.sugdct.Keys)
            {
                var sigdct = NSPackage.nimsuggest.sugdct[skey];
                if (sigdct["help"].Length > sig_help_default.Length)
                {
                    sig_help_default = sigdct["help"];
                }
            }

            foreach (string skey in NSPackage.nimsuggest.sugdct.Keys)
            {
                var sigdct = NSPackage.nimsuggest.sugdct[skey];
                //SortedDictionary<string,string>
                signatures.Add(SigAdd(subjectBuffer, skey, sigdct, sig_help_default, applicable_to_span, session));
            }

            //var currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            //var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0);
            //var applicableToSpan = currentSnapshot.CreateTrackingSpan(querySpan.Start.Position, 0, SpanTrackingMode.EdgeInclusive);

            //signatures.Add(CreateSignature(subjectBuffer, "add(int firstInt, int secondInt)", "Documentation for adding integers.", applicableToSpan));
            //signatures.Add(CreateSignature(subjectBuffer, "add(double firstDouble, double secondDouble)", "Documentation for adding doubles.", applicableToSpan));

            //string sighelp = "hey1";
            //if (sighelp != null) {
            //}
        }
Beispiel #8
0
            internal void ParamCurrentCalc()
            {
                if (m_session.IsDismissed == true || m_session == null)
                {
                    return;
                }

                NSUtil.DebugPrintAlways("NSSig - ParamCurrentCalc");
                if (m_parameters.Count == 0)
                {
                    this.CurrentParameter = null;
                    return;
                }

                //SnapshotPoint? point_trigger_null = m_session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot);
                SnapshotPoint point_trigger = (SnapshotPoint)m_session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot);

                var trigger_linenum = m_subjectBuffer.CurrentSnapshot.GetLineNumberFromPosition(point_trigger.Position);

                SnapshotPoint point_curr2 = m_session.TextView.Caret.Position.BufferPosition;
                SnapshotPoint point_curr  = (SnapshotPoint)m_session.TextView.BufferGraph.MapUpToBuffer(
                    point_curr2, PointTrackingMode.Positive, PositionAffinity.Successor, m_subjectBuffer.CurrentSnapshot.TextBuffer);
                //if (!point_curr2.HasValue) return;
                //SnapshotPoint point_curr = point_curr2.Value;
                var curr_linenum = m_subjectBuffer.CurrentSnapshot.GetLineNumberFromPosition(point_curr.Position);

                SnapshotPoint point_left = m_applicabletospan.GetStartPoint(m_subjectBuffer.CurrentSnapshot);

                string sig_str = m_applicabletospan.GetText(m_subjectBuffer.CurrentSnapshot);

                if (curr_linenum != trigger_linenum || point_curr < point_left)
                {
                    m_session.Dismiss();
                    return;
                }

                SnapshotPoint point_test = point_curr - 1;

                int commas_count = 0;

                while (true)
                {
                    if (point_test <= point_left)
                    {
                        break;
                    }
                    if (point_test.GetChar() == ',')
                    {
                        commas_count += 1;
                    }
                    if (point_test.GetChar() == ')')
                    {
                        m_session.Dismiss();
                        return;
                    }
                    point_test -= 1;
                }

                if (commas_count < m_parameters.Count)
                {
                    this.CurrentParameter = m_parameters[commas_count];
                }
                else
                {
                    this.CurrentParameter = m_parameters[m_parameters.Count - 1];
                }
                return;
            }