コード例 #1
0
        /// <summary>
        /// front endの初期化が終了したか調べる
        /// </summary>
        /// <returns></returns>
        public bool CheckFrontEndService()
        {
            if (tokenSource_.IsCancellationRequested)
            {
                return(false);
            }
            bool token = false;

            try
            {
                Monitor.TryEnter(context_, ref token);
                if (token)
                {
                    if (context_.worker == null)
                    {
                        return(false);
                    }
                    return(true);
                }
            }catch (Exception e) {
                HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
                logger_?.Error(e.ToString());
            }
            finally{
                if (token)
                {
                    Monitor.Exit(context_);
                }
            }
            return(false);
        }
コード例 #2
0
        public void Finalizer(int reason = 0)
        {
            logger_?.Trace("Enter Finalizer");
            try
            {
                tokenSource_?.Cancel();
                lock (context_)
                {
                    FinalizeContext();
                }
                UIThread.Finalizer();
            }
            catch (Exception e)
            {
                HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
                logger_?.Error(e.ToString());
            }

            diagnosticsTask_ = null;
            hoverTask_       = null;
            didChangeTask_   = null;

            dasmr_      = null;
            openedFile_ = null;

            /*tokenSource_ = null;
             * context_ = null;*/

            iniFile_ = null;

            logger_?.Trace("Leave Finalizer");
            logger_ = null;

            GC.Collect();
        }
コード例 #3
0
 LocationContainerImpl CommonImplementationsOfGoto(long hidemaruLine, long hidemaruColumn, InvokeWorker invoke, bool useContentsOfLine)
 {
     try
     {
         var absFileName = FileProc();
         if (String.IsNullOrEmpty(absFileName))
         {
             return(null);
         }
         long line, character;
         Hidemaru.HidemaruToZeroBase(out line, out character, hidemaruLine, hidemaruColumn);
         var locations = invoke(absFileName, line, character);
         List <LocationContainerImpl.WithContent> contents;
         if (useContentsOfLine)
         {
             contents = ConvertLocationsWidthContent(locations);
         }
         else
         {
             contents = ConvertLocations(locations);
         }
         return(new LocationContainerImpl(contents));
     }
     catch (Exception e)
     {
         logger_.Error(e.ToString());
     }
     return(null);
 }
コード例 #4
0
 DigOpenStatus DigOpen(string absFilename)
 {
     try
     {
         if (openedFile_.Filename == absFilename)
         {
             return(DigOpenStatus.AlreadyOpened);
         }
         var       text            = Hidemaru.GetTotalTextUnicode();
         const int contentsVersion = 1;
         context_.worker.DidOpen(absFilename, text, contentsVersion);
         openedFile_.Setup(absFilename,
                           new Uri(absFilename),
                           Hidemaru.GetUpdateCount(),
                           contentsVersion);
         return(DigOpenStatus.Opened);
     }
     catch (Exception e)
     {
         if (logger_ != null)
         {
             logger_.Error(e.ToString());
         }
     }
     return(DigOpenStatus.Failed);
 }
コード例 #5
0
 /// <summary>
 /// front endを初期化する(非同期版)
 /// </summary>
 /// <param name="serverConfigFilename"></param>
 /// <param name="currentSourceCodeDirectory"></param>
 public void InitializeFrontEndServiceAsync(string fileExtension, string currentSourceCodeDirectory)
 {
     var _ = Task.Run(async() =>
     {
         try
         {
             var prevUpdateCount = iniFile_.UpdateCount;
             while (InitializeFrontEndServiceMain(fileExtension, currentSourceCodeDirectory) == false)
             {
                 //リトライする(.iniファイルの読み込み失敗、または、LSPのプロセス起動失敗)
                 while (true)
                 {
                     if (tokenSource_.IsCancellationRequested)
                     {
                         return;
                     }
                     var currentUpdateCount = iniFile_.UpdateCount;
                     if (prevUpdateCount != currentUpdateCount)
                     {
                         //.iniファイルが更新されたため再読み込みする
                         prevUpdateCount = currentUpdateCount;
                         break;
                     }
                     await Task.Delay(500);
                 }
             }
             //.iniファイル読み込み成功
         }catch (Exception e)
         {
             HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
             logger_?.Error(e.ToString());
         }
     }, tokenSource_.Token);
 }
コード例 #6
0
 internal string Hover(long hidemaruLine, long hidemaruColumn)
 {
     try {
         if (context_.worker == null)
         {
             return("");
         }
         var absFileName = FileProc();
         if (String.IsNullOrEmpty(absFileName))
         {
             return("");
         }
         long line, character;
         Hidemaru.HidemaruToZeroBase(out line, out character, hidemaruLine, hidemaruColumn);
         var hover = context_.worker.Hover(absFileName, line, character);
         if (hover == null)
         {
             return("");
         }
         return(hover.contents.value);
     }
     catch (Exception e)
     {
         HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
         logger_.Error(e.ToString());
     }
     return("");
 }
コード例 #7
0
 public PositionImpl(HidemaruLspClient_BackEndContract.IPosition position)
 {
     if (position == null)
     {
         hidemaruCharacter_ = -1;
         hidemaruLine_      = -1;
         return;
     }
     Hidemaru.ZeroBaseToHidemaru(out hidemaruLine_,
                                 out hidemaruCharacter_,
                                 position.line,
                                 position.character);
 }
コード例 #8
0
 /// <summary>
 /// 秀丸エディタのテキストとサーバ側のテキストを明示的に同期する(デバッグ用途)
 /// </summary>
 /// <returns></returns>
 public bool SyncDocument()
 {
     try
     {
         var _ = FileProc();
     }catch (Exception e)
     {
         HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
         logger_.Error(e.ToString());
         return(false);
     }
     return(true);
 }
コード例 #9
0
 public LocationContainerImpl Implementation(long hidemaruLine, long hidemaruColumn)
 {
     try {
         if (context_.worker == null)
         {
             return(null);
         }
         return(CommonImplementationsOfGoto(hidemaruLine, hidemaruColumn, context_.worker.Implementation, false));
     }catch (Exception e) {
         HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
         logger_?.Error(e.ToString());
     }
     return(null);
 }
コード例 #10
0
        public DiagnosticsTask(IWorker worker, ILspClientLogger logger, CancellationToken cancellationToken)
        {
            hwndHidemaru_     = Hidemaru.Hidemaru_GetCurrentWindowHandle();
            outputPaneCleard_ = false;

            worker_            = worker;
            logger_            = logger;
            cancellationToken_ = cancellationToken;

            timer_          = new System.Windows.Forms.Timer();
            timer_.Interval = 500;
            timer_.Tick    += MainLoopAsync;
            timer_.Start();
        }
コード例 #11
0
            public Tooltipform(Service service, ILspClientLogger logger, CancellationToken cancellationToken)
            {
                service_      = service;
                hwndHidemaru_ = Hidemaru.Hidemaru_GetCurrentWindowHandle();

                logger_            = logger;
                cancellationToken_ = cancellationToken;

                SetFormAttr();
                SetLabelAttr();
                SetTimerAttr();
                //Memo:
                //Manual指定あり:formは意図した座標に表示される。
                //Manual指定なし:formをShow()したときにformが一瞬左上に表示される。
                this.StartPosition = FormStartPosition.Manual;
            }
コード例 #12
0
 public Service()
 {
     try
     {
         MicrosoftAppCenter.Start();
         tokenSource_ = new CancellationTokenSource();
         context_     = new Context();
         openedFile_  = new HidemaruEditorDocument();
         UIThread.Initializer();
         Hidemaru.Initialize();
     }catch (Exception e)
     {
         HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
         logger_?.Error(e.ToString());
     }
 }
コード例 #13
0
 /// <summary>
 /// BackEndを初期化する(同期版)
 /// </summary>
 /// <param name="logFilename"></param>
 /// <returns></returns>
 public bool InitializeBackEndService()
 {
     try
     {
         if (!InitializeBackEndServiceMain())
         {
             Finalizer();
             return(false);
         }
         return(true);
     }catch (Exception e)
     {
         HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
         logger_?.Error(e.ToString());
     }
     return(false);
 }
コード例 #14
0
 public ServerCapabilitiesImpl ServerCapabilities()
 {
     if (context_.worker == null)
     {
         return(null);
     }
     try
     {
         return(new ServerCapabilitiesImpl(context_.worker.ServerCapabilities));
     }
     catch (Exception e)
     {
         HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
         logger_.Error(e.ToString());
     }
     return(null);
 }
コード例 #15
0
 /// <summary>
 /// front endを初期化する(同期版)
 /// </summary>
 /// <param name="serverConfigFilename"></param>
 /// <param name="currentSourceCodeDirectory"></param>
 /// <returns></returns>
 public bool InitializeFrontEndService(string fileExtension, string currentSourceCodeDirectory)
 {
     try
     {
         var success = InitializeFrontEndServiceMain(fileExtension, currentSourceCodeDirectory);
         if (!success)
         {
             Finalizer();
             return(false);
         }
         return(true);
     }catch (Exception e)
     {
         HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
         logger_?.Error(e.ToString());
     }
     return(false);
 }
コード例 #16
0
 /// <summary>
 /// BackEndを初期化する(非同期版)
 /// </summary>
 /// <param name="logFilename"></param>
 public void InitializeBackEndServiceAsync()
 {
     var _ = Task.Run(() => {
         try
         {
             if (InitializeBackEndServiceMain())
             {
                 return;
             }
             UIThread.Invoke((MethodInvoker) delegate
             {
                 Finalizer();
             });
         }catch (Exception e)
         {
             HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
             logger_?.Error(e.ToString());
         }
     }, tokenSource_.Token);
 }
コード例 #17
0
            /// <summary>
            /// Tooltipを表示すべきかどうか調べる
            /// </summary>
            /// <returns></returns>
            bool ShouldTooltipBeDisplayed()
            {
                if (!IsActiveWindowIsHidemaruMainWindow())
                {
                    return(false);
                }
                if (!IsUnderWindowIsCurrentProcessWindow())
                {
                    return(false);
                }

                // 自分が先頭ではない
                IntPtr hWnd = Hidemaru.Hidemaru_GetCurrentWindowHandle();
                var    list = GetWindowHidemaruHandleList();

                if (list.Count > 0 && list[0] != hWnd)
                {
                    return(false);
                }
                return(true);
            }
コード例 #18
0
 /// <summary>
 /// textDocument/completion
 /// </summary>
 /// <param name="absFilename"></param>
 /// <param name="hidemaruLine"></param>
 /// <param name="hidemaruColumn"></param>
 /// <returns>一時的な辞書ファイル名(ファイルはCOM側で一定時間後に削除します)</returns>
 public string Completion(long hidemaruLine, long hidemaruColumn)
 {
     if (context_.worker == null)
     {
         return("");
     }
     try
     {
         var absFileName = FileProc();
         if (String.IsNullOrEmpty(absFileName))
         {
             return("");
         }
         long line, character;
         Hidemaru.HidemaruToZeroBase(out line, out character, hidemaruLine, hidemaruColumn);
         return(context_.worker.Completion(absFileName, line, character));
     }
     catch (Exception e)
     {
         HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
         logger_.Error(e.ToString());
     }
     return("");
 }
コード例 #19
0
        DigChangeStatus TryDigChange()
        {
            try
            {
                Debug.Assert(string.IsNullOrEmpty(openedFile_.Filename) == false);

                var currentUpdateCount = Hidemaru.GetUpdateCount();
                var prevUpdateCount    = openedFile_.hidemaruUpdateCount;
                if (currentUpdateCount == prevUpdateCount)
                {
                    return(DigChangeStatus.NoChanged);
                }
                openedFile_.UpdateContentsVersion(currentUpdateCount);
                context_.worker.DidChange(openedFile_.Filename, Hidemaru.GetTotalTextUnicode(), openedFile_.countentsVersion);
                return(DigChangeStatus.Changed);
            }catch (Exception e)
            {
                if (logger_ != null)
                {
                    logger_.Error(e.ToString());
                }
            }
            return(DigChangeStatus.Failed);
        }
コード例 #20
0
        public bool Initialize(string iniFileName)
        {
            //Memo: logger_はBackEndService起動後に取得可能
            try
            {
                iniFile_ = IniFileService.Create(iniFileName);
                if (iniFile_ == null)
                {
                    logger_?.Error(string.Format(".Ini file not found. iniFilename={0}", iniFileName));
                    return(false);
                }

                //CrashReport送信は個人情報に関わる処理なので処理の早い段階で真偽値をセットする
                MicrosoftAppCenter.EnableSendCrashReport = iniFile_.ReadEnableCrashReport();
                iniFile_.OnFileChanged += IniFile__OnFileChanged;

                return(true);
            }catch (Exception e)
            {
                HmOutputPane.OutputW(Hidemaru.Hidemaru_GetCurrentWindowHandle(), e.ToString());
                logger_?.Error(e.ToString());
            }
            return(false);
        }
コード例 #21
0
            async void MainLoop(object sender, EventArgs e)
            {
                if (cancellationToken_.IsCancellationRequested)
                {
                    timer_.Stop();
                    this.Close();
                    return;
                }
                if (ShouldTooltipBeDisplayed() == false)
                {
                    HideToolTips();
                    return;
                }

                string tooltipText = null;

                {
                    bool mouseMoved;
                    bool cursorMoved;
                    var  currentMousePoint        = new POINT(0, 0);
                    var  currentHidemaruPosition_ = new Hidemaru.Position(0, 0);


                    if (GetCursorPos(ref currentMousePoint) == false)
                    {
                        HideToolTips();
                        return;
                    }
                    mouseMoved      = prevMousePoint_ != currentMousePoint;
                    prevMousePoint_ = currentMousePoint;

                    if (Hidemaru.Hidemaru_GetCursorPosUnicode(ref currentHidemaruPosition_.line, ref currentHidemaruPosition_.column) == false)
                    {
                        HideToolTips();
                        return;
                    }
                    if (!currentHidemaruPosition_.ValueIsCorrect())
                    {
                        HideToolTips();
                        return;
                    }
                    cursorMoved           = prevHidemaruPosition_ != currentHidemaruPosition_;
                    prevHidemaruPosition_ = currentHidemaruPosition_;

                    if (mouseMoved)
                    {
                        if (cursorMoved)
                        {
                            //pass
                            return;
                        }
                        else
                        {
                            int line = 0, column = 0;
                            if (!Hidemaru.Hidemaru_GetCursorPosUnicodeFromMousePos(ref currentMousePoint, ref line, ref column))
                            {
                                HideToolTips();
                                return;
                            }
                            try
                            {
                                timer_.Stop();
                                tooltipText = await Task.Run(() => service_.Hover(line, column), cancellationToken_);
                            }
                            finally
                            {
                                timer_.Start();
                            }
                        }
                    }
                    else
                    {
                        if (cursorMoved)
                        {
                            HideToolTips();
                        }
                        else
                        {
                            //pass
                            return;
                        }
                    }
                }

                if ((tooltipText == null) || (tooltipText.Length == 0))
                {
                    HideToolTips();
                }
                else
                {
                    ShowToolTips(prevMousePoint_.x, prevMousePoint_.y, tooltipText);
                }
            }
コード例 #22
0
            // Zオーダー順に収められた秀丸ハンドルのリスト
            List <IntPtr> GetWindowHidemaruHandleList()
            {
                const uint    GW_HWNDPREV = 3;
                List <IntPtr> list        = new List <IntPtr>();
                IntPtr        hCurWnd     = Hidemaru.Hidemaru_GetCurrentWindowHandle();

                list.Add(hCurWnd);

                // 自分より前方を走査
                IntPtr hTmpWnd = hCurWnd;

                while (true)
                {
                    // 次のウィンドウ
                    hTmpWnd = GetWindow(hTmpWnd, GW_HWNDPREV);
                    if (hTmpWnd == IntPtr.Zero)
                    {
                        break;
                    }

                    // タブモードななので親があるハズ。(非タブモードだとそもそも1つしかない)
                    IntPtr hParent = GetParent(hTmpWnd);
                    if (hParent == IntPtr.Zero)
                    {
                        break;
                    }

                    // クラス名で判断
                    StringBuilder ClassName = new StringBuilder(256);
                    int           nRet      = GetClassName(hTmpWnd, ClassName, ClassName.Capacity);

                    if (ClassName.ToString().Contains(Hidemaru32Class_))
                    {
                        list.Insert(0, hTmpWnd);
                    }
                }

                // 一旦また自身のウィンドウハンドルにリセットして…
                hTmpWnd = hCurWnd;

                // 自分より後方を走査
                const uint GW_HWNDNEXT = 2;

                while (true)
                {
                    // 次のウィンドウ
                    hTmpWnd = GetWindow(hTmpWnd, GW_HWNDNEXT);
                    if (hTmpWnd == IntPtr.Zero)
                    {
                        break;
                    }

                    // タブモードななので親があるハズ。(非タブモードだとそもそも1つしかない)
                    IntPtr hParent = GetParent(hTmpWnd);
                    if (hParent == IntPtr.Zero)
                    {
                        break;
                    }

                    // クラス名で判断
                    StringBuilder ClassName = new StringBuilder(256);
                    int           nRet      = GetClassName(hTmpWnd, ClassName, ClassName.Capacity);

                    if (ClassName.ToString().Contains(Hidemaru32Class_))
                    {
                        list.Add(hTmpWnd);
                    }
                }

                return(list);
            }
コード例 #23
0
        /// <summary>
        /// ファイルの処理
        /// </summary>
        /// <returns>現在、秀丸エディタで開いているファイルの絶対パス</returns>
        string FileProc()
        {
            const string          fileNotFound = "";
            Func <string, string> fncDidOpen   = (absFileName) =>
            {
                switch (DigOpen(absFileName))
                {
                case DigOpenStatus.Opened:
                    return(absFileName);

                case DigOpenStatus.AlreadyOpened:
                    return(absFileName);

                case DigOpenStatus.Failed:
                    logger_.Warn("DigOpenStatus.Failed");
                    return(fileNotFound);

                default:
                    logger_.Warn("DigOpenStatus.???");
                    break;
                }
                return(fileNotFound);
            };

            string currentHidemaruFilePath;

            if (String.IsNullOrEmpty(openedFile_.Filename))
            {
                //初めてファイルを開く場合
                currentHidemaruFilePath = Hidemaru.GetFileFullPath();
                if (String.IsNullOrEmpty(currentHidemaruFilePath))
                {
                    return(fileNotFound);
                }
                return(fncDidOpen(currentHidemaruFilePath));
            }

            //
            //2回目以降にファイルを開く場合
            //
            currentHidemaruFilePath = Hidemaru.GetFileFullPath();
            if (string.IsNullOrEmpty(currentHidemaruFilePath))
            {
                //秀丸エディタのファイルが閉じた場合
                DidClose();
                return(fileNotFound);
            }

            if (openedFile_.Filename == currentHidemaruFilePath)
            {
                //秀丸エディタで前回と同じファイルを開いている場合
                if (TryDigChange() == DigChangeStatus.Failed)
                {
                    logger_.Warn("DigChangeStatus.Failed");
                    return(fileNotFound);
                }
                return(currentHidemaruFilePath);
            }

            //秀丸エディタで前回と異なるファイルを開いた場合
            DidClose();
            return(fncDidOpen(currentHidemaruFilePath));
        }