Skip to content

Commit fdf03aa

Browse files
committed
language-server: when looking for playerglobal.swc or airglobal.swc documentation, prefer playerglobal_rb.swc
Previously, we always used our bundled playerglobal XML docs. However, these are not necessarily complete for the newest AIR SDKs because Apache Flex didn't receive new updates from Adobe after a certain point. Includes a special case that checks for airglobal and selects playerglobal_rb.swc as a fallback for airglobal_rb.swc, which doesn't usually exist.
1 parent 0484093 commit fdf03aa

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

language-server/src/main/java/com/as3mxml/vscode/asdoc/VSCodePackageDITAParser.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,20 @@ private InputStream getPackageDITAStream(String packageName) {
382382
}
383383
InputStream stream = null;
384384
String fileName = new File(swcFilePath).getName();
385-
if (fileName.endsWith(".swc")
385+
String filePath = "docs/" + packageName + ".xml";
386+
ISWC swc = workspace.getSWCManager().get(new File(swcFilePath));
387+
if (swc == null) {
388+
return null;
389+
}
390+
try {
391+
ZipFile zipFile = new ZipFile(swc.getSWCFile());
392+
stream = SWCReader.getInputStream(zipFile, filePath);
393+
} catch (ZipException e) {
394+
return null;
395+
} catch (IOException e) {
396+
return null;
397+
}
398+
if (stream == null && fileName.endsWith(".swc")
386399
&& (fileName.contains("playerglobal") || fileName.contains("airglobal"))) {
387400
try {
388401
File jarPath = new File(VSCodePackageDITAParser.class.getProtectionDomain().getCodeSource()
@@ -395,20 +408,6 @@ private InputStream getPackageDITAStream(String packageName) {
395408
} catch (FileNotFoundException e) {
396409
return null;
397410
}
398-
} else {
399-
String filePath = "docs/" + packageName + ".xml";
400-
ISWC swc = workspace.getSWCManager().get(new File(swcFilePath));
401-
if (swc == null) {
402-
return null;
403-
}
404-
try {
405-
ZipFile zipFile = new ZipFile(swc.getSWCFile());
406-
stream = SWCReader.getInputStream(zipFile, filePath);
407-
} catch (ZipException e) {
408-
return null;
409-
} catch (IOException e) {
410-
return null;
411-
}
412411
}
413412
return stream;
414413
}

language-server/src/main/java/com/as3mxml/vscode/utils/DefinitionDocumentationUtils.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
public class DefinitionDocumentationUtils {
4848
private static final String SDK_LIBRARY_PATH_SIGNATURE_UNIX = "/frameworks/libs/";
4949
private static final String SDK_LIBRARY_PATH_SIGNATURE_WINDOWS = "\\frameworks\\libs\\";
50+
private static final String LOCALE_EN_US = "locale/en_US/";
51+
private static final String PLAYERGLOBAL = "playerglobal";
52+
private static final String AIRGLOBAL = "airglobal";
53+
private static final String RB_SWC_SUFFIX = "_rb.swc";
54+
private static final String FRAMEWORKS = "frameworks";
55+
private static final String FILE_EXTENSION_SWC = ".swc";
5056

5157
public static String getDocumentationForDefinition(IDefinition definition, boolean useMarkdown,
5258
ICompilerProject project, boolean allowDITA) {
@@ -96,7 +102,8 @@ private static VSCodeASDocComment getCommentForDefinition(IDocumentableDefinitio
96102
boolean useMarkdown, IWorkspace workspace, boolean allowDITA) {
97103
VSCodeASDocComment comment = (VSCodeASDocComment) documentableDefinition.getExplicitSourceComment();
98104
String definitionFilePath = documentableDefinition.getContainingFilePath();
99-
if (allowDITA && comment == null && definitionFilePath != null && definitionFilePath.endsWith(".swc")) {
105+
if (allowDITA && comment == null && definitionFilePath != null
106+
&& definitionFilePath.endsWith(FILE_EXTENSION_SWC)) {
100107
IDITAList ditaList = null;
101108
File swcFile = new File(definitionFilePath);
102109
if (swcFile.exists()) {
@@ -105,24 +112,34 @@ private static VSCodeASDocComment getCommentForDefinition(IDocumentableDefinitio
105112
String fileName = swcFile.getName();
106113
ditaList = swc.getDITAList();
107114

108-
// next, if it's a SDK/framework liberary, check for an
115+
// next, if it's a SDK/framework library, check for an
109116
// associated resource bundle .swc
110117
if (ditaList == null && (definitionFilePath.contains(SDK_LIBRARY_PATH_SIGNATURE_UNIX)
111118
|| definitionFilePath.contains(SDK_LIBRARY_PATH_SIGNATURE_WINDOWS))) {
112-
String rbName = fileName.substring(0, fileName.length() - 4) + "_rb.swc";
119+
String swcBaseName = fileName.substring(0, fileName.length() - 4);
120+
String rbName = swcBaseName + RB_SWC_SUFFIX;
113121
File frameworksDir = swcFile.getParentFile();
114-
while (!frameworksDir.getName().equals("frameworks")) {
122+
while (!frameworksDir.getName().equals(FRAMEWORKS)) {
115123
frameworksDir = frameworksDir.getParentFile();
116124
}
117-
File rbSwcFile = new File(frameworksDir, "locale/en_US/" + rbName);
125+
File rbSwcFile = new File(frameworksDir, LOCALE_EN_US + rbName);
118126
if (rbSwcFile.exists()) {
119127
ISWC rbSwc = workspace.getSWCManager().get(rbSwcFile);
120128
ditaList = rbSwc.getDITAList();
129+
} else if (fileName.contains(AIRGLOBAL)) {
130+
// airglobal_rb.swc may not exist, but
131+
// playerglobal_rb.swc may be used as a fallback
132+
rbName = PLAYERGLOBAL + RB_SWC_SUFFIX;
133+
rbSwcFile = new File(frameworksDir, LOCALE_EN_US + rbName);
134+
if (rbSwcFile.exists()) {
135+
ISWC rbSwc = workspace.getSWCManager().get(rbSwcFile);
136+
ditaList = rbSwc.getDITAList();
137+
}
121138
}
122139
}
123140
// finally, fall back to the bundled documentation for
124141
// playerglobal or airglobal, if the filename matches
125-
if (ditaList == null && (fileName.contains("playerglobal") || fileName.contains("airglobal"))) {
142+
if (ditaList == null && (fileName.contains(PLAYERGLOBAL) || fileName.contains(AIRGLOBAL))) {
126143
try {
127144
File jarPath = new File(DefinitionDocumentationUtils.class.getProtectionDomain().getCodeSource()
128145
.getLocation().toURI());

0 commit comments

Comments
 (0)