Skip to content

Commit

Permalink
implement include handling fix (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed May 9, 2024
1 parent 0218d4c commit 60782ae
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
3 changes: 2 additions & 1 deletion spin2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Possible next additions:

Update P2 Only

- BUGFIX: parsing repair detection of alignl/alignw in VAR Issue(#9)
- BUGFIX: parsing repair detection of alignl/alignw in VAR. Issue(#9)
- BUGFIX: FlexSpin support: implement new understanding. #include is including spin code but no longer needs spin/spin2 file extension. Issue(#11)

## [2.2.16] 2024-04-14

Expand Down
8 changes: 8 additions & 0 deletions spin2/TEST_LANG_SERVER/spin2/240509-fixes.spin2
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ VAR

alignl
byte curdir[MAX_PATH+1],tmppath[MAX_PATH+1]

' -----------------------------------------------

#include "dummy-spin-but-not.inc"

PUB main() | lclVar

lclVar := MAX_BYTES
3 changes: 3 additions & 0 deletions spin2/TEST_LANG_SERVER/spin2/dummy-spin-but-not.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
con

MAX_BYTES = 4
30 changes: 15 additions & 15 deletions spin2/server/src/DocumentProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ export default class DocumentProcessor {

if (includedFiles.length > 0) {
// convert to matching filespecs
const resolved = await resolveReferencedIncludes(includedFiles, currDocumentInProcess.folder, this.ctx);
this.ctx.logger.log(`TRC: -- STEP back from resolveReferencedIncludes()...`);
const resolved: string[] = await resolveReferencedIncludes(includedFiles, currDocumentInProcess.folder, this.ctx);
this.ctx.logger.log(`TRC: -- STEP back from resolveReferencedIncludes()... resolved=[${resolved}]`);
currDocumentInProcess.pushReferencedFileSpecs(...resolved);
this.ctx.logger.log(`TRC: -- STEP scan the includes...`);
if (currDocumentInProcess.referencedFileSpecsCount == 0) {
Expand Down Expand Up @@ -276,11 +276,11 @@ export default class DocumentProcessor {
this.ctx.logger.log(`TRC: -- STEP incorporate included docs into maps ...`);
const objectReferences: Map<string, string> =
skipIncludeScan == false ? currDocumentFindings.includedObjectNamesByFilename() : new Map<string, string>();
const includes: string[] = currDocumentFindings.includeNamesForFilename(fileName);
const includeNames: string[] = currDocumentFindings.includeNamesForFilename(fileName);
this.ctx.logger.log(
`TRC: [${currDocumentFindings.instanceName()}] nameHashKeys=[${Array.from(objectReferences.keys())}], nameHashValues=[${Array.from(
objectReferences.values()
)}], includedFiles=[${includes}]`
)}], includedFiles=[${includeNames}]`
);
const objectNames: string[] = Array.from(objectReferences.keys());
const objectFileNames: string[] = Array.from(objectReferences.values());
Expand All @@ -294,7 +294,7 @@ export default class DocumentProcessor {
`TRC: [${currDocumentFindings.instanceName()}] clear() previous findings but NOT include info so can load included documents`
);
//
// connnect our child objects so document will hightlight child references
// connnect our child objects so document will highlight child references
for (let index = 0; index < objectNames.length; index++) {
const objectName = objectNames[index];
const objectSpinFilename = objectFileNames[index];
Expand Down Expand Up @@ -324,16 +324,18 @@ export default class DocumentProcessor {
}
}
if (!bFound) {
this.ctx.logger.log(`TRC: NO include filename matches found!`);
this.ctx.logger.log(`TRC: NO object filename matches found!`);
}
}
//
// load symbols from included files so document will hightlight these symbols as well
for (let index = 0; index < includes.length; index++) {
const includeFilename = includes[index];
// load symbols from included files so document will highlight these symbols as well
for (let index = 0; index < includeNames.length; index++) {
const includeFilename = includeNames[index];
const includeSpinFilename = includeFilename;
let matchFilename: string = includeFilename.toLowerCase();
if (!matchFilename?.toLowerCase().includes('.spin')) {
// allow filenames such as name.inc where fileType is present but NOT .spin or .spin2
const hasFileExt: boolean = path.basename(matchFilename).includes('.');
if (!matchFilename?.toLowerCase().includes('.spin') && hasFileExt == false) {
matchFilename = `${matchFilename}.`.toLowerCase();
}
this.ctx.logger.log(`TRC: MATCHING includeFilename=[${includeFilename}], matchFilename=[${matchFilename}]`);
Expand Down Expand Up @@ -393,11 +395,9 @@ export default class DocumentProcessor {
// return depth-first list of included files
const parsedDoc: ProcessedDocument | undefined = this.ctx.docsByFSpec.get(FSpec);
if (parsedDoc) {
if (parsedDoc.referencedFileSpecsCount > 0) {
for (let index = 0; index < parsedDoc.referencedFileSpecsCount; index++) {
const includeFSpec = parsedDoc.referencedFileSpec(index);
this._getParseList(includeFSpec, resultList);
}
for (let index = 0; index < parsedDoc.referencedFileSpecsCount; index++) {
const includeFSpec = parsedDoc.referencedFileSpec(index);
this._getParseList(includeFSpec, resultList);
}
}
// only 1 copy of each fileSpec, please!
Expand Down
15 changes: 9 additions & 6 deletions spin2/server/src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,25 @@ export function resolveReferencedIncludes(includedFiles: string[], rootDirSpec:
const matchedFiles: string[] = [];
ctx.logger.log(`TRC: resolveReferencedIncludes(includedFiles=[${includedFiles}], rootDirSpec=[${rootDirSpec}])`);

const fileSpecs: string[] = getSpinFilesInDirSync(rootDirSpec, ctx);
const fileSpecs: string[] = getSpinFilesInDirSync(rootDirSpec, includedFiles, ctx);
ctx.logger.log(`TRC: found fileSpecs=[${fileSpecs}]`);
for (let index = 0; index < includedFiles.length; index++) {
const fileBaseName = includedFiles[index];
const hasFileExt: boolean = fileBaseName.includes('.');
let matchFilename: string = fileBaseName.toLowerCase();
if (!fileBaseName.toLowerCase().includes('.spin')) {
if (!fileBaseName.toLowerCase().includes('.spin') && hasFileExt == false) {
matchFilename = `${fileBaseName}.`.toLowerCase();
}
//ctx.logger.log(`TRC: looking for matchFilename=[${matchFilename}]`);
ctx.logger.log(`TRC: looking for matchFilename=[${matchFilename}]`);
for (let index = 0; index < fileSpecs.length; index++) {
const fileSpec: string = fileSpecs[index];
const pathParts: string[] = fileSpec.split(/[/\\]/).filter(Boolean); // handle windows/linux paths
const fileName = pathParts[pathParts.length - 1].toLowerCase();
//ctx.logger.log(`TRC: found fileSpec=[${fileSpec}], pathParts=[${pathParts}](${pathParts.length}), fileName=[${fileName}]`);
//ctx.logger.log(`TRC: checking fileSpec=[${fileSpec}]`);
ctx.logger.log(`TRC: checking fileSpec=[${fileSpec}]`);
if (fileName.startsWith(matchFilename)) {
matchedFiles.push(fileSpec);
//ctx.logger.log(`TRC: matched fileSpec=[${fileSpec}]`);
ctx.logger.log(`TRC: matched fileSpec=[${fileSpec}]`);
}
}
}
Expand Down Expand Up @@ -198,7 +199,7 @@ export function fileExists(pathSpec: string): boolean {
return existsStatus;
}

export function getSpinFilesInDirSync(dirSpec: string, ctx: Context): string[] {
export function getSpinFilesInDirSync(dirSpec: string, includedFiles: string[], ctx: Context): string[] {
const resultList: string[] = [];
const url = new URL(dirSpec, 'file://');
//const pathSpec = fileURLToPath(dirSpec);
Expand All @@ -208,6 +209,8 @@ export function getSpinFilesInDirSync(dirSpec: string, ctx: Context): string[] {
tmpFiles.forEach((file) => {
if (isSpinExt(file)) {
resultList.push(path.join(dirSpec, file));
} else if (includedFiles.includes(file)) {
resultList.push(path.join(dirSpec, file));
}
});
} else {
Expand Down

0 comments on commit 60782ae

Please sign in to comment.