예제 #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 JavaUnconfiguredEditor Unconfigure(IWpfTextView textView, Collection <ITextBuffer> subjectBuffers)
        {
            var oldEditor = Disconnect(textView, subjectBuffers);

            string                 fileName               = VSHelpers.GetFileName(textView);
            EclipseWorkspace       eclipseWorkspace       = EclipseWorkspace.FromFilePath(fileName);
            JavaUnconfiguredEditor javaUnconfiguredEditor = null;

            javaUnconfiguredEditor = textView.Properties.GetOrCreateSingletonProperty <JavaUnconfiguredEditor>(() => new JavaUnconfiguredEditor(subjectBuffers, textView, JavaPkgServerMgr, eclipseWorkspace));
            Telemetry.Client.Get().TrackEvent("App.EditorOpenUnconfigured");

            if (oldEditor != null)
            {
                oldEditor.Fire_EditorReplaced(javaUnconfiguredEditor);
            }

            foreach (var buffer in subjectBuffers)
            {
                buffer.Properties.AddProperty(typeof(JavaUnconfiguredEditor), javaUnconfiguredEditor);
            }

            return(javaUnconfiguredEditor);
        }
예제 #3
0
        public async Task ParseAsync()
        {
            FileParseResponse = null;
            TokenSource       = new CancellationTokenSource();
            var token      = TokenSource.Token;
            var textReader = new TextSnapshotToTextReader(TextSnapshot) as TextReader;

            await Task.Run(async() =>
            {
                // Trottle down parsing; wait another 200ms
                Thread.Sleep(TimeSpan.FromMilliseconds(200));
                if (token.IsCancellationRequested)
                {
                    return;
                }

                Trace.WriteLine("[@@ Java parser] getting ready to parse");
                var astRequest  = ProtocolHandlers.CreateFileParseRequest(textReader, VSHelpers.GetFileName(Parent.TextView));
                var astResponse = await Parent.JavaPkgServer.Send(Parent, astRequest);
                if (astResponse.responseType == Protocol.Response.ResponseType.FileParseStatus && astResponse.fileParseResponse != null)
                {
                    Trace.WriteLine(String.Format("Response from server: {0} {1}",
                                                  astResponse.fileParseResponse.status.ToString(),
                                                  string.IsNullOrEmpty(astResponse.fileParseResponse.errorMessage) ? astResponse.fileParseResponse.errorMessage : astResponse.fileParseResponse.fileIdentifier.ToString()));

                    if (astResponse.fileParseResponse.status)
                    {
                        // We have a successful parse; now we keep going asking questions about the AST
                        FileParseResponse = astResponse.fileParseResponse;

                        // Squiggles
                        var messagesRequest  = ProtocolHandlers.CreateFileParseMessagesRequest(astResponse.fileParseResponse.fileIdentifier);
                        var messagesResponse = await Parent.JavaPkgServer.Send(Parent, messagesRequest);
                        if (messagesResponse.responseType == Protocol.Response.ResponseType.FileParseMessages && messagesResponse.fileParseMessagesResponse != null)
                        {
                            Parent.Fire_FileParseMessagesAvailable(this, messagesResponse.fileParseMessagesResponse);
                        }

                        // Outline
                        var outlineRequest  = ProtocolHandlers.CreateOutlineFileRequest(astResponse.fileParseResponse.fileIdentifier);
                        var outlineResponse = await Parent.JavaPkgServer.Send(Parent, outlineRequest);
                        if (outlineResponse.responseType == Protocol.Response.ResponseType.OutlineResults && outlineResponse.outlineResultResponse != null)
                        {
                            Parent.Fire_OutlineResponseAvailable(this, outlineResponse.outlineResultResponse);
                        }

                        // We leave the AST in the cache in order to service any QuickInfo operations
                    }
                }
            }, token);
        }
예제 #4
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);
        }