Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go to included file #105

Merged
merged 2 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- Structure macros support
- Open file from include directive

### Fixed

Expand Down
12 changes: 12 additions & 0 deletions client/src/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ suite('Test include', () => {
test('Definitions are correct', async () => {
const mainUri = getDocUri(path.resolve(includeFolder, 'simple.asm'));
await openUseCaseFile(mainUri);

const theLinkDefinitions = await commands.executeCommand<Location[]>('vscode.executeDefinitionProvider', mainUri, {
line: 1,
character: 12,
Expand All @@ -162,6 +163,17 @@ suite('Test include', () => {
const theLinkDefinition = theLinkDefinitions[0];
assert.deepEqual(theLinkDefinition.uri, getDocUri(path.resolve(includeFolder, 'simpleInclude.asm')));
assert.deepEqual(theLinkDefinition.range, constructRange(0, 0, 7));

const includeFileDefinitions = await commands.executeCommand<Location[]>('vscode.executeDefinitionProvider', mainUri, {
line: 0,
character: 20,
});
assert.ok(includeFileDefinitions, 'No include file definitions');
assert.strictEqual(includeFileDefinitions.length, 1, "include file definitions size");
const includeFileDefinition = includeFileDefinitions[0];
assert.deepEqual(includeFileDefinition.uri, getDocUri(path.resolve(includeFolder, 'simpleInclude.asm')));
assert.deepEqual(includeFileDefinition.range, constructRange(0, 0, 0));

const anotherDefinitions = await commands.executeCommand<Location[]>('vscode.executeDefinitionProvider', mainUri, {
line: 4,
character: 12,
Expand Down
4 changes: 3 additions & 1 deletion server/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INCBIN, INCDIR, INCLUDE, LIST, NAMES, REND, RORG, SEG, SET, SETSTR, SUB
import { getFolder, isFileExists, isDirExists, joinUri, unifyUri } from "./localFiles";
import { MSG } from "./messages";
import { ParsedFiles } from "./parsedFiles";
import { AllComandNode, ArgumentNode, CommandNode, ExpressionNode, FileNode, IdentifierNode, IfDirectiveNode, LabelNode, LineNode, MacroDirectiveNode, NodeType, RepeatDirectiveNode } from "./parser/ast/nodes";
import { AllComandNode, ArgumentNode, AstNode, CommandNode, ExpressionNode, FileNode, IdentifierNode, IfDirectiveNode, LabelNode, LineNode, MacroDirectiveNode, NodeType, RepeatDirectiveNode } from "./parser/ast/nodes";
import { LabelsByName, LabelObject, ALIASES, mergeLabelsMap } from "./parser/ast/labels";
import { constructError, constructWarning, DiagnosticWithURI } from "./validators/util";
import { operations } from "./dasm/operations";
Expand All @@ -28,6 +28,7 @@ export class Program {
public includeFolders = new Set<string>();
public errors: DiagnosticWithURI[] = [];
public usedFiles = new Set<string>();
public includedFiles = new Map<AstNode, string>();
private currentlyIncludedStack = new Set<string>();
public macrosCalls: MacrosCalls;
public dynamicLabelsPrefixes = new Set<string>();
Expand Down Expand Up @@ -175,6 +176,7 @@ export class Program {
if (!fileName) return;
const fileUri = this.findFileUri(fileName);
if (fileUri) {
this.includedFiles.set(fileNameNode, fileUri);
if (this.uri === fileUri || this.currentlyIncludedStack.has(fileUri)) {
this.errors.push(constructError(MSG.CIRCULAR_INCLUDE, fileNameNode));
} else {
Expand Down
16 changes: 14 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TextDocument } from 'vscode-languageserver-textdocument';
import {
createConnection, DefinitionParams, HoverParams, InitializeParams, ReferenceParams, TextDocumentPositionParams, TextDocuments, TextDocumentSyncKind} from 'vscode-languageserver/node';
createConnection, DefinitionParams, HoverParams, InitializeParams, Location, Range, ReferenceParams, TextDocumentPositionParams, TextDocuments, TextDocumentSyncKind} from 'vscode-languageserver/node';
import { onCompletionImpl, onCompletionResolveImpl } from './completion/basic';
import { getHover } from './hovering/basic';
import { ParsedFiles } from './parsedFiles';
import { LabelsByName } from './parser/ast/labels';
import { MacrosByName } from './parser/ast/macros';
import { AstNode } from './parser/ast/nodes';
import { AstNode, FileNode } from './parser/ast/nodes';
import { getNodeByPosition } from './parser/ast/utils';
import { Program } from './program';
import { validateProgram } from './validators/general';
Expand Down Expand Up @@ -114,6 +114,7 @@ function rescanDocuments() {
collectLabels(program.globalLabels);
program.localLabels.forEach(it => collectLabels(it));
collectMacros(program.macroses);
collectIncludes(program.includedFiles);
});
const usedFiles = new Set<string>();
const diagnostics: DiagnosticWithURI[] = [];
Expand Down Expand Up @@ -167,5 +168,16 @@ function collectMacros(macrosMap: MacrosByName) {
}
}

function collectIncludes(includes: Map<AstNode, string>) {
for (const [node, uri] of includes.entries()) {
const fileNode = new FileNode(Location.create(uri, Range.create(0, 0, 0, 0)), []);
const relatedObject: RelatedObject = {
definitions: [fileNode],
usages: []
};
relatedObjects.set(node, relatedObject);
}
}

documents.listen(connection);
connection.listen();