Ejemplo n.º 1
0
        /// <summary>
        /// Fully initializes the EditorContext.
        /// </summary>
        public EditorContext(ITextEditor editor)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            this.Editor      = editor;
            this.CaretLine   = editor.Caret.Line;
            this.CaretColumn = editor.Caret.Column;
            if (CaretColumn > 1 && editor.Document.GetText(editor.Document.PositionToOffset(CaretLine, CaretColumn - 1), 1) == ";")
            {
                // If caret is just after ';', pretend that caret is before ';'
                // (works well e.g. for this.Foo();(*caret*) - we want to get "this.Foo()")
                // This is equivalent to pretending that ; don't exist, and actually it's not such a bad idea.
                CaretColumn -= 1;
            }

            this.CurrentExpression       = GetExpressionAtCaret(editor);
            this.CurrentSymbol           = ResolveExpression(CurrentExpression, editor, CaretLine, CaretColumn);
            this.CurrentParseInformation = ParserService.GetExistingParseInformation(editor.FileName);

            this.CurrentLine    = editor.Document.GetLine(CaretLine);
            this.CurrentLineAST = GetCurrentLineAst(this.CurrentLine, editor);

            this.CurrentMemberAST = GetCurrentMemberAST(editor);

            this.CurrentElement = FindInnermostNode(this.CurrentMemberAST, new Location(CaretColumn, CaretLine));
//			DebugLog();
        }
Ejemplo n.º 2
0
        public static void Init()
        {
            if (init)
            {
                return;
            }

            init   = true;
            worker = new WorkerThread();

            thread = new Thread(
                delegate() {
                LoggingService.Info("start background compiler");
                worker.RunLoop();
            }
                );

            thread.IsBackground = true;
            thread.Name         = "CSBackgroundCompiler";

            ParserService.ParserUpdateStepFinished += delegate {
                if (WorkbenchSingleton.Workbench.ActiveViewContent == null)
                {
                    return;
                }

                if (ParserService.LoadSolutionProjectsThreadRunning)
                {
                    return;
                }

                ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;

                if (provider == null)
                {
                    return;
                }

                ParseInformation parseInfo = ParserService.GetExistingParseInformation(provider.TextEditor.FileName);

                if (parseInfo == null)
                {
                    return;
                }

                string          fileName    = provider.TextEditor.FileName;
                string          fileContent = provider.TextEditor.Document.Text;
                IProjectContent pc          = parseInfo.CompilationUnit.ProjectContent;

                if (currentWork == null)
                {
                    thread.Start();
                }

                if (currentWork == null || currentWork.IsCompleted)
                {
                    currentWork = worker.Enqueue(() => RunCompile(fileName, fileContent, pc));
                }
            };
        }
Ejemplo n.º 3
0
        static IClass GetCurrentClass(ITextEditor editor)
        {
            var parseInfo = ParserService.GetExistingParseInformation(editor.FileName);

            if (parseInfo != null)
            {
                return(parseInfo.CompilationUnit.GetInnermostClass(editor.Caret.Line, editor.Caret.Column));
            }
            return(null);
        }
Ejemplo n.º 4
0
        void FetchParseInformation()
        {
            ParseInformation parseInfo = ParserService.GetExistingParseInformation(this.FileName);

            if (parseInfo == null)
            {
                // if parse info is not yet available, start parsing on background
                ParserService.BeginParse(this.FileName, primaryTextEditorAdapter.Document);
                // we'll receive the result using the ParseInformationUpdated event
            }
            ParseInformationUpdated(parseInfo);
        }
		void AddAllMembersMatchingText(string text)
		{
			ITextEditor editor = GetEditor();
			if (editor != null) {
				ParseInformation parseInfo = ParserService.GetExistingParseInformation(editor.FileName);
				if (parseInfo != null) {
					foreach (IClass c in parseInfo.CompilationUnit.Classes) {
						AddAllMembersMatchingText(c, text, true);
					}
				}
			}
		}
Ejemplo n.º 6
0
        IClass GetCurrentClass(Task item)
        {
            // Tasks are created by parsing, so the parse information for item.FileName should already be present.
            // If they aren't, that's because the file might have been deleted/renamed in the meantime.
            // We use GetExistingParseInformation to avoid trying to parse a file that might have been deleted/renamed.
            ParseInformation parseInfo = ParserService.GetExistingParseInformation(item.FileName);

            if (parseInfo != null)
            {
                IClass c = parseInfo.CompilationUnit.GetInnermostClass(item.Line, item.Column);
                if (c != null)
                {
                    return(c);
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
        protected override void Initialize()
        {
            base.Initialize();
            IProjectContent projectContent = ParserService.GetProjectContent(Project);

            if (projectContent != null)
            {
                Nodes.Clear();
                ReferenceFolderNode referencesNode = new ReferenceFolderNode(Project);
                referencesNode.AddTo(this);
                projectContent.ReferencedContentsChanged += delegate { WorkbenchSingleton.SafeThreadAsyncCall(referencesNode.UpdateReferenceNodes); };
                foreach (ProjectItem item in Project.GetItemsOfType(ItemType.Compile))
                {
                    ParseInformation parseInformation = ParserService.GetExistingParseInformation(item.FileName);
                    if (parseInformation != null)
                    {
                        InsertParseInformation(parseInformation.CompilationUnit);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 void UpdateParseInformationForFolding()
 {
     UpdateParseInformationForFolding(ParserService.GetExistingParseInformation(this.Adapter.FileName));
 }
Ejemplo n.º 9
0
 public ICompilationUnit GetCompilationUnit(string fileName)
 {
     return(ParserService.GetExistingParseInformation(fileName).CompilationUnit);
 }
Ejemplo n.º 10
0
 public ParseInformation GetExistingParseInformation(IProjectContent content, string fileName)
 {
     return(ParserService.GetExistingParseInformation(content, fileName));
 }