예제 #1
0
        public ServerProxy Configure(string eclipsePath)
        {
            Telemetry.Client.Get().TrackEvent("App.ConfigureEditor");

            // Remove itself from properties
            TextView.Properties.RemoveProperty(typeof(JavaUnconfiguredEditor));

            // Set path in registry
            Registry.SetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\JavaPkgSrv", "EclipseInstall", eclipsePath, RegistryValueKind.String);

            // Reboot editor
            var fileName         = VSHelpers.GetFileName(TextView);
            var eclipseWorkspace = EclipseWorkspace.FromFilePath(fileName);
            var javaPkgServer    = JavaPkgServerManager.GetProxy(eclipseWorkspace);
            var javaEditor       = new JavaEditor(SubjectBuffers, TextView, javaPkgServer, eclipseWorkspace);

            Telemetry.Client.Get().TrackEvent("App.EditorOpenConfigured");

            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;
                }
            });

            TextView.Properties.RemoveProperty(typeof(ServerProxy));
            TextView.Properties.AddProperty(typeof(ServerProxy), javaPkgServer);

            TextView.Properties.RemoveProperty(typeof(JavaEditor));
            TextView.Properties.AddProperty(typeof(JavaEditor), javaEditor);

            foreach (var buffer in SubjectBuffers)
            {
                buffer.Properties.RemoveProperty(typeof(JavaUnconfiguredEditor));
                buffer.Properties.RemoveProperty(typeof(ServerProxy));
                buffer.Properties.AddProperty(typeof(ServerProxy), javaPkgServer);
                buffer.Properties.RemoveProperty(typeof(JavaEditor));
                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(javaPkgServer);
        }
예제 #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);
        }