Skip to content

Commit

Permalink
Merge pull request #5 from IgorGaming/main
Browse files Browse the repository at this point in the history
Added support for anonymous index components.
  • Loading branch information
Naoray authored Oct 28, 2021
2 parents 7827cf4 + 599b85a commit bf3fdd4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
workspace,
ProviderResult,
} from "vscode";
import { nameToPath } from "./utils";
import { nameToIndexPath, nameToPath } from "./utils";

export default class HoverProvider implements BaseHoverProvider {
public provideHover(
Expand All @@ -25,11 +25,15 @@ export default class HoverProvider implements BaseHoverProvider {
}

const componentName = doc.getText(range);
const componentPath = nameToPath(componentName);
const workspacePath = workspace.getWorkspaceFolder(doc.uri)?.uri.fsPath;

let componentPath = nameToPath(componentName);

if (!existsSync(workspacePath + componentPath)) {
return;
componentPath = nameToIndexPath(componentName);

if (!existsSync(workspacePath + componentPath)) {
return;
}
}

const lookUpUri = `[${componentPath}](${Uri.file(
Expand Down
34 changes: 20 additions & 14 deletions src/linkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
DocumentLink,
Range,
} from "vscode";
import { nameToPath } from "./utils";
import { nameToIndexPath, nameToPath } from "./utils";

export default class LinkProvider implements DocumentLinkProvider {
public provideDocumentLinks(
Expand All @@ -32,20 +32,26 @@ export default class LinkProvider implements DocumentLinkProvider {

if (result !== null) {
for (let componentName of result) {
const componentPath = nameToPath(componentName);

if (existsSync(workspacePath + componentPath)) {
let start = new Position(
line.lineNumber,
line.text.indexOf(componentName)
);
let end = start.translate(0, componentName.length);
let documentlink = new DocumentLink(
new Range(start, end),
Uri.file(workspacePath + componentPath)
);
documentLinks.push(documentlink);
let componentPath = nameToPath(componentName);

if (!existsSync(workspacePath + componentPath)) {
componentPath = nameToIndexPath(componentName);

if (!existsSync(workspacePath + componentPath)) {
continue;
}
}

let start = new Position(
line.lineNumber,
line.text.indexOf(componentName)
);
let end = start.translate(0, componentName.length);
let documentlink = new DocumentLink(
new Range(start, end),
Uri.file(workspacePath + componentPath)
);
documentLinks.push(documentlink);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function nameToPath(path: string): string {
return `/resources/views/components/${path.replace(/\./g, "/")}.blade.php`;
}

export function nameToIndexPath(path: string): string {
return `/resources/views/components/${path.replace(/\./g, "/")}/index.blade.php`;
}

0 comments on commit bf3fdd4

Please sign in to comment.