1
1
/*******************************************************************************
2
- * Copyright (c) 2016-2017 Red Hat Inc. and others.
2
+ * Copyright (c) 2016-2022 Red Hat Inc. and others.
3
3
* All rights reserved. This program and the accompanying materials
4
4
* are made available under the terms of the Eclipse Public License 2.0
5
5
* which accompanies this distribution, and is available at
12
12
*******************************************************************************/
13
13
package org .eclipse .jdt .ls .core .internal .handlers ;
14
14
15
+ import java .util .Arrays ;
16
+ import java .util .HashSet ;
17
+ import java .util .List ;
18
+ import java .util .Set ;
19
+
15
20
import org .eclipse .core .resources .IFile ;
21
+ import org .eclipse .core .resources .IProject ;
22
+ import org .eclipse .core .resources .ResourcesPlugin ;
23
+ import org .eclipse .core .runtime .IPath ;
16
24
import org .eclipse .jdt .ls .core .internal .JDTUtils ;
25
+ import org .eclipse .jdt .ls .core .internal .ResourceUtils ;
17
26
import org .eclipse .jdt .ls .core .internal .managers .ProjectsManager ;
18
27
import org .eclipse .lsp4j .TextDocumentIdentifier ;
19
28
@@ -25,17 +34,53 @@ public class ProjectConfigurationUpdateHandler {
25
34
26
35
private ProjectsManager projectManager ;
27
36
28
- ProjectConfigurationUpdateHandler (ProjectsManager projectManager ) {
37
+ public ProjectConfigurationUpdateHandler (ProjectsManager projectManager ) {
29
38
this .projectManager = projectManager ;
30
39
}
31
40
41
+ /**
42
+ * Update the projects' configurations (build files).
43
+ *
44
+ * @param identifiers the identifiers which may point to the projects' paths or
45
+ * files that belong to some projects in the workspace.
46
+ */
47
+ public void updateConfigurations (List <TextDocumentIdentifier > identifiers ) {
48
+ Set <IProject > projects = new HashSet <>();
49
+ for (TextDocumentIdentifier identifier : identifiers ) {
50
+ IProject project = getProjectFromUri (identifier .getUri ());
51
+ if (project != null ) {
52
+ projects .add (project );
53
+ continue ;
54
+ }
55
+ IFile file = JDTUtils .findFile (identifier .getUri ());
56
+ if (file == null ) {
57
+ continue ;
58
+ }
59
+ project = file .getProject ();
60
+ if (project != null ) {
61
+ projects .add (project );
62
+ }
63
+ }
64
+
65
+ for (IProject project : projects ) {
66
+ // most likely the handler is invoked intentionally by the user, that's why
67
+ // we force the update despite no changes of in build descriptor being made
68
+ projectManager .updateProject (project , true );
69
+ }
70
+ }
71
+
32
72
public void updateConfiguration (TextDocumentIdentifier param ) {
33
- IFile file = JDTUtils .findFile (param .getUri ());
34
- if (file == null ) {
35
- return ;
73
+ updateConfigurations (Arrays .asList (param ));
74
+ }
75
+
76
+ private IProject getProjectFromUri (String uri ) {
77
+ IPath uriPath = ResourceUtils .canonicalFilePathFromURI (uri );
78
+ IProject [] projects = ResourcesPlugin .getWorkspace ().getRoot ().getProjects ();
79
+ for (IProject project : projects ) {
80
+ if (project .getLocation ().equals (uriPath )) {
81
+ return project ;
82
+ }
36
83
}
37
- // most likely the handler is invoked intentionally by the user, that's why
38
- // we force the update despite no changes of in build descriptor being made
39
- projectManager .updateProject (file .getProject (), true );
84
+ return null ;
40
85
}
41
86
}
0 commit comments