Skip to content

Commit

Permalink
Revert "Fixed ts server plugin"
Browse files Browse the repository at this point in the history
This reverts commit 6f4f51d.
  • Loading branch information
AleksandrsKondratjevs committed Oct 18, 2022
1 parent 20e1744 commit 425c471
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 65 deletions.
114 changes: 56 additions & 58 deletions build-packages/ts-server-plugin/lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,62 +313,60 @@ export class Cache {
// + it is dependent on https://github.com/microsoft/TypeScript/issues/50300
// and https://github.com/microsoft/TypeScript/issues/40824

getDeclarationInlayHintsForFile(fileName: string): ts.InlayHint[] {
// Method hints hint on amount of plugins for this method
const refsOrDecs = this.fileToNamespaceMap[fileName] || [];

return refsOrDecs.reduce((acc, refOrDec) => {
if (refOrDec instanceof NamespaceReference) {
// ^^^ we only care about namespace declarations
return acc;
}

const referenceNodes = refOrDec.getNodesByTargetConfig();
const pluginHints = referenceNodes.reduce((acc, node) => {
const nodeFileName = node.getSourceFile().fileName;

if (nodeFileName !== fileName) {
return acc;
}
// ^^^ we only care about nodes in the same file
const plugins = this.getReferencesByNamespace(refOrDec.getNamespaceString());

if (!plugins.length) {
return acc;
}

let position = node.getEnd();

if (ts.isPropertyDeclaration(node.parent)) {
position = node.parent.name.getEnd();
}

if (ts.isMethodDeclaration(node.parent)) {
const [closeParenToken] = this.ctx.nodeUtils.getNodeChildByCondition(
node.parent,
(n) => n.kind === ts.SyntaxKind.CloseParenToken,
);

if (closeParenToken) {
position = closeParenToken.getEnd();
}
}

return [
...acc,
{
text: `⬅ has ${plugins.length} plugin${plugins.length > 1 ? 's' : ''}`,
position,
kind: ts.InlayHintKind.Parameter,
whitespaceBefore: true,
},
];
}, [] as ts.InlayHint[]);

return [
...acc,
...pluginHints,
];
}, [] as ts.InlayHint[]);
}
// getDeclarationInlayHintsForFile(fileName: string): ts.InlayHint[] {
// // Method hints hint on amount of plugins for this method
// const refsOrDecs = this.fileToNamespaceMap[fileName] || [];

// return refsOrDecs.reduce((acc, refOrDec) => {
// if (refOrDec instanceof NamespaceReference) {
// // ^^^ we only care about namespace declarations
// return acc;
// }

// const referenceNodes = refOrDec.getNodesByTargetConfig();
// const pluginHints = referenceNodes.reduce((acc, node) => {
// const nodeFileName = node.getSourceFile().fileName;
// if (nodeFileName !== fileName) {
// return acc;
// }
// // ^^^ we only care about nodes in the same file
// const plugins = this.getReferencesByNamespace(refOrDec.getNamespaceString());
// if (!plugins.length) {
// return acc;
// }

// let position = node.getEnd();

// if (ts.isPropertyDeclaration(node.parent)) {
// position = node.parent.name.getEnd();
// }

// if (ts.isMethodDeclaration(node.parent)) {
// const [closeParenToken] = this.ctx.nodeUtils.getNodeChildByCondition(
// node.parent,
// (n) => n.kind === ts.SyntaxKind.CloseParenToken
// );

// if (closeParenToken) {
// position = closeParenToken.getEnd();
// }
// }

// return [
// ...acc,
// {
// text: `⬅ has ${plugins.length} plugin${plugins.length > 1 ? 's' : ''}`,
// position,
// kind: ts.InlayHintKind.Parameter,
// whitespaceBefore: true
// }
// ];
// }, [] as ts.InlayHint[]);

// return [
// ...acc,
// ...pluginHints
// ];
// }, [] as ts.InlayHint[]);
// }
}
14 changes: 7 additions & 7 deletions build-packages/ts-server-plugin/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ function init(): ts.server.PluginModule {
}

// eslint-disable-next-line arrow-body-style
proxy.provideInlayHints = (fileName: string, span: ts.TextSpan): ts.InlayHint[] => {
// vvv Ignore original inline hints
// eslint-disable-next-line arrow-body-style
return cache.getDeclarationInlayHintsForFile(fileName).filter((inlayHint) => {
return inlayHint.position > span.start && inlayHint.position < span.start + span.length;
});
};
// proxy.provideInlayHints = (fileName: string, span: ts.TextSpan): ts.InlayHint[] => {
// // vvv Ignore original inline hints
// // eslint-disable-next-line arrow-body-style
// return cache.getDeclarationInlayHintsForFile(fileName).filter((inlayHint) => {
// return inlayHint.position > span.start && inlayHint.position < span.start + span.length;
// });
// };

proxy.getSemanticDiagnostics = (fileName: string): ts.Diagnostic[] => {
const diagnostics = info.languageService.getSemanticDiagnostics(fileName);
Expand Down
1 change: 1 addition & 0 deletions build-packages/ts-server-plugin/lib/util/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export class NodeUtils {
textSpan,
fileName: node.getSourceFile().fileName,
isWriteAccess: true, // TODO: get if this plugin is editable
isDefinition: false
};
}
}

0 comments on commit 425c471

Please sign in to comment.