コード例 #1
0
ファイル: JavaEditor.cs プロジェクト: XewTurquish/vsminecraft
        public JavaEditor(Collection<ITextBuffer> subjectBuffers, IWpfTextView textView, ServerProxy javaPkgServer, EclipseWorkspace eclipseWorkspace)
            : base(subjectBuffers, textView, eclipseWorkspace)
        {
            JavaPkgServer = javaPkgServer;
            OnIdleQueue = new Dictionary<object,Action>();
            IdleActions = new List<Action>(3);
            TypeRootIdentifier = null;
            ParserEnabled = true;

            JavaPkgServer.TerminatedAbnormally += JavaPkgServer_TerminatedAbnormally;
        }
コード例 #2
0
        public static JavaEditor Configure(IWpfTextView textView, Collection<ITextBuffer> subjectBuffers)
        {
            var oldEditor = Disconnect(textView, subjectBuffers);

            EclipseWorkspace eclipseWorkspace = null;
            Protocol.TypeRootIdentifier presetTypeRootIdentifier = null;

            string fileName = VSHelpers.GetFileName(textView);
            if (DefinitionCache.ContainsKey(fileName))
            {
                eclipseWorkspace = DefinitionCache[fileName].Item1;
                presetTypeRootIdentifier = DefinitionCache[fileName].Item2;
                DefinitionCache.Remove(fileName);
            }
            else if (File.Exists(fileName + ".id"))
            {
                string[] info = File.ReadAllLines(fileName + ".id");
                if (info.Length >= 2)
                {
                    eclipseWorkspace = EclipseWorkspace.FromRootPath(info[0]);
                    presetTypeRootIdentifier = new Protocol.TypeRootIdentifier();
                    presetTypeRootIdentifier.handle = info[1];
                }
            }
            else
                eclipseWorkspace = EclipseWorkspace.FromFilePath(fileName);

            var javaPkgServer = JavaPkgServerMgr.GetProxy(eclipseWorkspace);
            JavaEditor javaEditor = null;
            if (javaPkgServer != null)
            {
                textView.Properties.AddProperty(typeof(ServerProxy), javaPkgServer);

                javaEditor = textView.Properties.GetOrCreateSingletonProperty<JavaEditor>(() => new JavaEditor(subjectBuffers, textView, javaPkgServer, eclipseWorkspace));
                Telemetry.Client.Get().TrackEvent("App.EditorOpenConfigured");

                if (presetTypeRootIdentifier == null)
                {
                    javaPkgServer.Send(javaEditor, ProtocolHandlers.CreateOpenTypeRootRequest(fileName)).ContinueWith((System.Threading.Tasks.Task<Protocol.Response> responseTask) =>
                    {
                        var openTypeResponse = responseTask.Result;

                        if (openTypeResponse.responseType == Protocol.Response.ResponseType.OpenTypeRoot &&
                            openTypeResponse.openTypeRootResponse != null)
                        {
                            javaEditor.TypeRootIdentifier = openTypeResponse.openTypeRootResponse.typeRootIdentifier;
                        }
                    });
                }
                else if (File.Exists(fileName + ".id"))
                {
                    // Reopening a .class file from the cache
                    javaPkgServer.Send(javaEditor, ProtocolHandlers.CreataAddTypeRootRequest(presetTypeRootIdentifier)).ContinueWith((System.Threading.Tasks.Task<Protocol.Response> responseTask) =>
                    {
                        var addTypeResponse = responseTask.Result;

                        if (addTypeResponse.responseType == Protocol.Response.ResponseType.AddTypeRoot &&
                            addTypeResponse.addTypeRootResponse != null)
                        {
                            javaEditor.TypeRootIdentifier = addTypeResponse.addTypeRootResponse.typeRootIdentifier;
                        }
                    });
                    javaEditor.DisableParsing(); // No need to parse .class files from .jar for squiggles
                }
                else
                {
                    // Usually preset when opening a source file from a .jar via gotodef 
                    javaEditor.TypeRootIdentifier = presetTypeRootIdentifier;
                    javaEditor.DisableParsing(); // No need to parse .class files from .jar for squiggles
                }
            }
            else
                return null;

            if (oldEditor != null)
                oldEditor.Fire_EditorReplaced(javaEditor);

            foreach (var buffer in subjectBuffers)
            {
                buffer.Properties.AddProperty(typeof(ServerProxy), javaPkgServer);
                buffer.Properties.AddProperty(typeof(JavaEditor), javaEditor);

                JavaOutline outline = null;
                if (buffer.Properties.TryGetProperty<JavaOutline>(typeof(JavaOutline), out outline))
                {
                    outline.JavaEditor = javaEditor;
                }

                JavaSquiggles squiggles = null;
                if (buffer.Properties.TryGetProperty<JavaSquiggles>(typeof(JavaSquiggles), out squiggles))
                {
                    squiggles.JavaEditor = javaEditor;
                }
            }
            return javaEditor;
        }