示例#1
0
        public ViewItem(ITextView view, ABnfFactory factory, ABnf abnf, ProjectInfo project, uint item_id
                        , string full_path, string text, long version)
        {
            m_left_pairs.Add("(", ")");
            m_left_pairs.Add("[", "]");
            m_left_pairs.Add("<", ">");
            m_left_pairs.Add("{", "}");

            m_right_pairs.Add(")", "(");
            m_right_pairs.Add("]", "[");
            m_right_pairs.Add(">", "<");
            m_right_pairs.Add("}", "{");

            // 保存相关信息
            m_view      = view;
            m_factory   = factory;
            m_abnf      = abnf;
            m_project   = project;
            m_item_id   = item_id;
            m_full_path = full_path;

            UpdateText(view, text, version);
            UpdateError();
            UpdateReference();
        }
示例#2
0
 public FileItem(ProjectInfo project, ABnf abnf, string full_path, uint item_id, ABnfFile file)
 {
     m_project   = project;
     m_abnf      = abnf;
     m_full_path = full_path;
     m_item_id   = item_id;
     m_file      = file;
 }
示例#3
0
 public ProjectInfo(ABnfFactory factory, ABnf abnf, string path)
 {
     // 保存基本信息
     m_dot_ext = factory.GetDotExt();
     m_factory = factory;
     m_abnf    = abnf;
     m_path    = path;
 }
示例#4
0
        // 创建分析对象
        protected ABnfFile CreateABnfFile(ABnf abnf, string text)
        {
            var file = m_factory.CreateABnfFile(m_full_path, abnf, text);

            if (file == null)
            {
                file = new ABnfFileInfo(m_full_path, abnf, text);
            }
            file.SetProjectInfo(m_project);
            return(file);
        }
示例#5
0
        public UIViewItem(ABnf abnf, ABnf abnf_ui, IWpfTextView view
                          , SVsServiceProvider provider, IVsEditorAdaptersFactoryService adapters_factory
                          , UIProjectInfo project, uint item_id, string full_path, ABnfFactory factory, string line_comment_begin)
        {
            m_left_pairs.Add("(", ")");
            m_left_pairs.Add("[", "]");
            m_left_pairs.Add("<", ">");
            m_left_pairs.Add("{", "}");

            m_right_pairs.Add(")", "(");
            m_right_pairs.Add("]", "[");
            m_right_pairs.Add(">", "<");
            m_right_pairs.Add("}", "{");

            // 保存相关信息
            m_abnf               = abnf;
            m_abnf_ui            = abnf_ui;
            m_factory            = factory;
            m_view               = view;
            m_buffer             = m_view.TextBuffer;
            m_provider           = provider;
            m_project            = project;
            m_item_id            = item_id;
            m_adapters_factory   = adapters_factory;
            m_full_path          = full_path;
            m_line_comment_begin = line_comment_begin;

            if (m_view.Properties.TryGetProperty("version", out long version))
            {
                m_view.Properties.RemoveProperty("version");
            }
            ++version;
            m_view.Properties.AddProperty("version", version);
            string text = m_view.TextBuffer.CurrentSnapshot.GetText().Clone() as string;

            string project_path = null;

            if (m_project != null)
            {
                project_path = m_project.GetProjectPath();
                m_project.AddViewItem(m_item_id, this);
            }
            if (m_view.Properties.TryGetProperty(nameof(ALanguageServer), out ALanguageServer server))
            {
                server.AddTask(() => server.UpdateViewContent(m_view, project_path, m_item_id, m_full_path, text, version));
            }

            m_view.TextBuffer.Changed += OnBufferChanged;
            m_view.GotAggregateFocus  += OnViewFocusIn;
            m_view.LostAggregateFocus += OnViewFocusOut;
        }
        public void Start(ABnfFactory factory)
        {
            m_factory = factory;
            if (m_factory == null)
            {
                return;
            }
            m_abnf = ALanguageUtility.CreateABnf(m_factory);
            if (m_abnf == null)
            {
                return;
            }

            StartThread();
        }
        // 创建abnf解析器
        public static ABnf CreateABnf(ABnfFactory factory)
        {
            var bytes = factory.LoadABnf();

            if (bytes == null)
            {
                return(null);
            }

            ABnf abnf = new ABnf();

            char[] chars = new char[bytes.Length];
            for (int i = 0; i < bytes.Length; ++i)
            {
                chars[i] = (char)bytes[i];
            }
            if (abnf.Load(new string(chars), factory) != null)
            {
                return(null);
            }
            return(abnf);
        }
示例#8
0
        // 创建分析对象
        protected FileItem CreatFileItem(ABnf abnf, string full_path, uint node)
        {
            // 读取文件
            var text = File.ReadAllText(full_path);

            // 创建ABnfFile
            var file = m_factory.CreateABnfFile(full_path, abnf, text);

            if (file == null)
            {
                file = new ABnfFile(full_path, abnf, text);
            }
            file.SetProjectInfo(this);

            // 创建item
            var file_item = m_factory.CreateFileItem(this, abnf, full_path, node, file);

            if (file_item == null)
            {
                file_item = new FileItem(this, abnf, full_path, node, file);
            }
            return(file_item);
        }
 public ABnfFileInfo(string full_path, ABnf abnf, string text) : base(full_path, abnf, text)
 {
 }
 public override ABnfFile CreateABnfFile(string full_path, ABnf abnf, string text)
 {
     return(new ALittleScriptFile(full_path, abnf, text));
 }
 public override ProjectInfo CreateProjectInfo(ABnfFactory factory, ABnf abnf, string path)
 {
     return(new AProtobufProjectInfo(factory, abnf, path));
 }
示例#12
0
 public ALittleScriptFile(string full_path, ABnf abnf, string text) : base(full_path, abnf, text)
 {
 }
 public override ABnfFile CreateABnfFile(string full_path, ABnf abnf, string text)
 {
     return(new AProtobufFile(full_path, abnf, text));
 }
 public override FileItem CreateFileItem(ProjectInfo project, ABnf abnf, string full_path, uint item_id, ABnfFile file)
 {
     return(new AProtobufFileItem(project, abnf, full_path, item_id, file));
 }
示例#15
0
 public virtual FileItem CreateFileItem(ProjectInfo project, ABnf abnf, string full_path, uint item_id, ABnfFile file)
 {
     return(null);
 }
示例#16
0
 public virtual ABnfFile CreateABnfFile(string full_path, ABnf abnf, string text)
 {
     return(null);
 }
示例#17
0
 public UIABnfFile(string full_path, ABnf abnf_ui, string text) : base(full_path, abnf_ui, text)
 {
 }
示例#18
0
 public virtual ProjectInfo CreateProjectInfo(ABnfFactory factory, ABnf abnf, string path)
 {
     return(null);
 }
        public void VsTextViewCreated(IVsTextView text_view)
        {
            if (ALanguageUtility.s_service_provider == null)
            {
                ALanguageUtility.s_service_provider = m_service_provider;
            }

            if (m_factory == null)
            {
                return;
            }

            SaveAdapterFactory();
            m_factory.Init(m_service_provider, m_adapters_factory);

            // 获取系统单例,用于打开文件
            if (m_open_document == null)
            {
                m_open_document = m_service_provider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            }

            // 获取视窗
            IWpfTextView view = m_adapters_factory.GetWpfTextView(text_view);

            if (view == null)
            {
                return;
            }

            // 添加关闭监听
            view.Closed += OnViewClosed;

            // 创建ABnf
            if (m_abnf == null)
            {
                m_abnf = ALanguageUtility.CreateABnf(m_factory);
            }
            if (m_abnf == null)
            {
                return;
            }
            if (m_abnf_ui == null)
            {
                m_abnf_ui = ALanguageUtility.CreateABnf(m_factory);
            }
            if (m_abnf_ui == null)
            {
                return;
            }

            // 获取高亮tag
            if (m_highlight_tag == null)
            {
                m_highlight_tag = m_factory.CreateTextMarkerTag();
            }

            if (m_highlight_tag != null)
            {
                view.Properties.AddProperty(nameof(TextMarkerTag), m_highlight_tag);
            }

            // 获取全路径
            string full_path = ALanguageUtility.GetFilePath(view);

            if (full_path == null)
            {
                return;
            }

            var solution = m_factory.GetSolution();

            if (solution == null)
            {
                return;
            }

            var server = solution.GetServer();

            if (server != null)
            {
                view.Properties.AddProperty(nameof(ALanguageServer), server);
                view.TextBuffer.Properties.AddProperty(nameof(ALanguageServer), server);
            }
            view.Properties.AddProperty(nameof(IVsTextView), text_view);

            // 获取所在的工程
            m_open_document.IsDocumentInAProject(full_path, out IVsUIHierarchy project, out uint item_id, out Microsoft.VisualStudio.OLE.Interop.IServiceProvider _ppSP, out int _pDocInProj);
            UIProjectInfo project_info = null;

            if (project != null)
            {
                solution.GetProjects().TryGetValue(project, out project_info);
            }

            // 创建信息,并作为属性给view
            var info = new UIViewItem(m_abnf, m_abnf_ui, view, m_service_provider, m_adapters_factory, project_info, item_id, full_path, m_factory, m_factory.GetLineCommentBegin());

            view.Properties.AddProperty(nameof(UIViewItem), info);
            view.TextBuffer.Properties.AddProperty(nameof(UIViewItem), info);

            // 提前添加各种source
            {
                if (!view.TextBuffer.Properties.TryGetProperty(nameof(ALanguageCompletionSource), out ALanguageCompletionSource source))
                {
                    source = new ALanguageCompletionSource(view.TextBuffer);
                    view.TextBuffer.Properties.AddProperty(nameof(ALanguageCompletionSource), source);
                }
            }
            {
                if (!view.TextBuffer.Properties.TryGetProperty(nameof(ALanguageQuickInfoSource), out ALanguageQuickInfoSource source))
                {
                    source = new ALanguageQuickInfoSource(view.TextBuffer);
                    view.TextBuffer.Properties.AddProperty(nameof(ALanguageQuickInfoSource), source);
                }
            }
            {
                if (!view.TextBuffer.Properties.TryGetProperty(nameof(ALanguageSignatureHelpSource), out ALanguageSignatureHelpSource source))
                {
                    source = new ALanguageSignatureHelpSource(view.TextBuffer);
                    view.TextBuffer.Properties.AddProperty(nameof(ALanguageSignatureHelpSource), source);
                }
            }

            {
                if (!view.Properties.TryGetProperty(nameof(ALanguageErrorTagger), out ALanguageErrorTagger tagger))
                {
                    tagger = new ALanguageErrorTagger(view);
                    view.Properties.AddProperty(nameof(ALanguageErrorTagger), tagger);
                }
            }

            {
                if (!view.Properties.TryGetProperty(nameof(ALanguageReferenceTagger), out ALanguageReferenceTagger tagger))
                {
                    tagger = new ALanguageReferenceTagger(view);
                    view.Properties.AddProperty(nameof(ALanguageReferenceTagger), tagger);
                }
            }

            {
                if (!view.Properties.TryGetProperty(nameof(ALanguageHighlightWordTagger), out ALanguageHighlightWordTagger tagger))
                {
                    tagger = new ALanguageHighlightWordTagger(view);
                    view.Properties.AddProperty(nameof(ALanguageHighlightWordTagger), tagger);
                }
            }

            // 添加命令
            {
                ALanguageGotoDefinitionCommand filter = new ALanguageGotoDefinitionCommand(view);
                text_view.AddCommandFilter(filter, out IOleCommandTarget next);
                filter.Next = next;
                view.Properties.AddProperty(nameof(ALanguageGotoDefinitionCommand) + "Target", next);
            }

            {
                ALanguageCompletionCommand filter = new ALanguageCompletionCommand(view, m_completion_broker);
                text_view.AddCommandFilter(filter, out IOleCommandTarget next);
                filter.Next = next;
                view.Properties.AddProperty(nameof(ALanguageCompletionCommand) + "Target", next);
                view.Properties.AddProperty(nameof(ALanguageCompletionCommand), filter);
            }
        }
 public override ProjectInfo CreateProjectInfo(ABnfFactory factory, ABnf abnf, string path)
 {
     return(new ALittleScriptProjectInfo(factory, abnf, path));
 }
示例#21
0
 public ABnfLangFile(string full_path, ABnf abnf, string text) : base(full_path, abnf, text)
 {
 }
 public AProtobufProjectInfo(ABnfFactory factory, ABnf abnf, string path)
     : base(factory, abnf, path)
 {
 }
示例#23
0
 public ABnfFile(string full_path, ABnf abnf, string text)
 {
     m_abnf      = abnf;
     m_text      = text;
     m_full_path = full_path;
 }