Skip to content

Commit

Permalink
Fix #130 Stop resolving definitions after the line
Browse files Browse the repository at this point in the history
If a build stage name shadows an actual image that was used previously,
trying to resolve the definition of the actual name should not end up
jumping forward to the build stage name.

Signed-off-by: Remy Suen <remy.suen@docker.com>
  • Loading branch information
rcjsuen committed Aug 4, 2024
1 parent 3830bee commit fd6622b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
### Added
- support preparing renames for here-documents ([#129](https://github.com/rcjsuen/dockerfile-language-service/issues/129))

### Fixed
- stop resolving definitions to build stages after the selected line ([#130](https://github.com/rcjsuen/dockerfile-language-service/issues/130))

## [0.14.0] - 2024-06-18
### Added
- support computing highlight ranges for heredocs ([#121](https://github.com/rcjsuen/dockerfile-language-service/issues/121))
Expand Down
2 changes: 1 addition & 1 deletion src/dockerDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class DockerDefinition {
if (Util.isInsideRange(position, range)) {
const stageName = instruction.getImageName();
for (const from of dockerfile.getFROMs()) {
if (stageName === from.getBuildStage()) {
if (stageName === from.getBuildStage() && from.getRange().start.line < range.start.line) {
return from.getBuildStageRange();
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/dockerDefinition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ describe("Dockerfile Document Definition tests", function () {
let location = computeDefinition(document, Position.create(1, 10));
assert.strictEqual(location, null);
});

describe("stage name shadowing an image", () => {
it("referencing a later stage", () => {
const document = "FROM alpine\nFROM scratch AS alpine";
let location = computeDefinition(document, Position.create(0, 8));
assert.strictEqual(location, null);

location = computeDefinition(document, Position.create(1, 19));
assertLocation(location, 1, 16, 1, 22);
});

it("referencing itself", () => {
const document = "FROM alpine AS alpine";
let location = computeDefinition(document, Position.create(0, 8));
assert.strictEqual(location, null);

location = computeDefinition(document, Position.create(0, 18));
assertLocation(location, 0, 15, 0, 21);
});
});
});
});

Expand Down

0 comments on commit fd6622b

Please sign in to comment.