Skip to content

Commit dc37492

Browse files
committed
Responded to PR feedback
1 parent 5790e5f commit dc37492

File tree

69 files changed

+681
-423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+681
-423
lines changed

apps/api-extractor/src/api/ExtractorConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ interface IExtractorConfigParameters {
162162
docModelEnabled: boolean;
163163
apiJsonFilePath: string;
164164
docModelIncludeForgottenExports: boolean;
165+
projectFolderUrl: string | undefined;
165166
rollupEnabled: boolean;
166167
untrimmedFilePath: string;
167168
alphaTrimmedFilePath: string;
@@ -257,6 +258,8 @@ export class ExtractorConfig {
257258
public readonly apiJsonFilePath: string;
258259
/** {@inheritDoc IConfigDocModel.includeForgottenExports} */
259260
public readonly docModelIncludeForgottenExports: boolean;
261+
/** {@inheritDoc IConfigDocModel.projectFolderUrl} */
262+
public readonly projectFolderUrl: string | undefined;
260263

261264
/** {@inheritDoc IConfigDtsRollup.enabled} */
262265
public readonly rollupEnabled: boolean;
@@ -317,6 +320,7 @@ export class ExtractorConfig {
317320
this.docModelEnabled = parameters.docModelEnabled;
318321
this.apiJsonFilePath = parameters.apiJsonFilePath;
319322
this.docModelIncludeForgottenExports = parameters.docModelIncludeForgottenExports;
323+
this.projectFolderUrl = parameters.projectFolderUrl;
320324
this.rollupEnabled = parameters.rollupEnabled;
321325
this.untrimmedFilePath = parameters.untrimmedFilePath;
322326
this.alphaTrimmedFilePath = parameters.alphaTrimmedFilePath;
@@ -894,6 +898,7 @@ export class ExtractorConfig {
894898
let docModelEnabled: boolean = false;
895899
let apiJsonFilePath: string = '';
896900
let docModelIncludeForgottenExports: boolean = false;
901+
let projectFolderUrl: string | undefined;
897902
if (configObject.docModel) {
898903
docModelEnabled = !!configObject.docModel.enabled;
899904
apiJsonFilePath = ExtractorConfig._resolvePathWithTokens(
@@ -902,6 +907,7 @@ export class ExtractorConfig {
902907
tokenContext
903908
);
904909
docModelIncludeForgottenExports = !!configObject.docModel.includeForgottenExports;
910+
projectFolderUrl = configObject.docModel.projectFolderUrl;
905911
}
906912

907913
let tsdocMetadataEnabled: boolean = false;
@@ -1009,6 +1015,7 @@ export class ExtractorConfig {
10091015
docModelEnabled,
10101016
apiJsonFilePath,
10111017
docModelIncludeForgottenExports,
1018+
projectFolderUrl,
10121019
rollupEnabled,
10131020
untrimmedFilePath,
10141021
alphaTrimmedFilePath,

apps/api-extractor/src/api/IConfigFile.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,21 @@ export interface IConfigDocModel {
141141
*
142142
* @defaultValue `false`
143143
*/
144-
includeForgottenExports?: boolean;
144+
includeForgottenExports?: boolean;
145+
146+
/**
147+
* The URL to the `<projectFolder>` token where the project's source code can be viewed on a website like GitHub or
148+
* Azure DevOps.
149+
*
150+
* @remarks
151+
* This URL is concatenated with the file paths serialized to the doc model to produce URL file paths to individual API items.
152+
* For example, if the `projectFolderUrl` is "https://github.com/microsoft/rushstack/tree/main/apps/api-extractor" and an API
153+
* item's file path is "api/ExtractorConfig.ts", the full URL file path would be
154+
* "https://github.com/microsoft/rushstack/tree/main/apps/api-extractor/api/ExtractorConfig.js".
155+
*
156+
* Can be omitted if you don't care about including source code links in your API documentation reference.
157+
*/
158+
projectFolderUrl?: string;
145159
}
146160

147161
/**

apps/api-extractor/src/collector/MessageRouter.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ export class MessageRouter {
204204
// NOTE: Since compiler errors pertain to issues specific to the .d.ts files,
205205
// we do not apply source mappings for them.
206206
const sourceFile: ts.SourceFile = diagnostic.file;
207-
const sourceLocation: ISourceLocation = this._sourceMapper.getSourceLocationFromFileAndPos(
207+
const sourceLocation: ISourceLocation = this._sourceMapper.getSourceLocation({
208208
sourceFile,
209-
diagnostic.start || 0,
210-
true /* useDtsLocation */
211-
);
209+
pos: diagnostic.start || 0,
210+
useDtsLocation: true
211+
});
212212
options.sourceFilePath = sourceLocation.sourceFilePath;
213213
options.sourceFileLine = sourceLocation.sourceFileLine;
214214
options.sourceFileColumn = sourceLocation.sourceFileColumn;
@@ -260,10 +260,10 @@ export class MessageRouter {
260260
text: message.unformattedText
261261
};
262262

263-
const sourceLocation: ISourceLocation = this._sourceMapper.getSourceLocationFromFileAndPos(
263+
const sourceLocation: ISourceLocation = this._sourceMapper.getSourceLocation({
264264
sourceFile,
265-
message.textRange.pos
266-
);
265+
pos: message.textRange.pos
266+
});
267267
options.sourceFilePath = sourceLocation.sourceFilePath;
268268
options.sourceFileLine = sourceLocation.sourceFileLine;
269269
options.sourceFileColumn = sourceLocation.sourceFileColumn;
@@ -378,10 +378,10 @@ export class MessageRouter {
378378
properties
379379
};
380380

381-
const sourceLocation: ISourceLocation = this._sourceMapper.getSourceLocationFromFileAndPos(
381+
const sourceLocation: ISourceLocation = this._sourceMapper.getSourceLocation({
382382
sourceFile,
383383
pos
384-
);
384+
});
385385
options.sourceFilePath = sourceLocation.sourceFilePath;
386386
options.sourceFileLine = sourceLocation.sourceFileLine;
387387
options.sourceFileColumn = sourceLocation.sourceFileColumn;

apps/api-extractor/src/collector/SourceMapper.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ export interface ISourceLocation {
4141
sourceFileColumn: number;
4242
}
4343

44+
export interface IGetSourceLocationOptions {
45+
/**
46+
* The source file to get the source location from.
47+
*/
48+
sourceFile: ts.SourceFile;
49+
50+
/**
51+
* The position within the source file to get the source location from.
52+
*/
53+
pos: number;
54+
55+
/**
56+
* If `false` or not provided, then we attempt to follow source maps in order to resolve the
57+
* location to the original `.ts` file. If resolution isn't possible for some reason, we fall
58+
* back to the `.d.ts` location.
59+
*
60+
* If `true`, then we don't bother following source maps, and the location refers to the `.d.ts`
61+
* location.
62+
*/
63+
useDtsLocation?: boolean;
64+
}
65+
4466
export class SourceMapper {
4567
// Map from .d.ts file path --> ISourceMap if a source map was found, or null if not found
4668
private _sourceMapByFilePath: Map<string, ISourceMap | null> = new Map<string, ISourceMap | null>();
@@ -51,28 +73,18 @@ export class SourceMapper {
5173
/**
5274
* Given a `.d.ts` source file and a specific position within the file, return the corresponding
5375
* `ISourceLocation`.
54-
*
55-
* @remarks
56-
* If `useDtsLocation` is `false` (default), then we attempt to follow source maps in order to resolve
57-
* the location to the original `.ts` file. If resolution isn't possible for some reason, we fall back
58-
* to the `.d.ts` location.
59-
*
60-
* If `useDtsLocation` is `true`, then we don't bother following source maps, and the location refers
61-
* to the `.d.ts` location.
6276
*/
63-
public getSourceLocationFromFileAndPos(
64-
sourceFile: ts.SourceFile,
65-
pos: number,
66-
useDtsLocation: boolean = false
67-
): ISourceLocation {
68-
const lineAndCharacter: ts.LineAndCharacter = sourceFile.getLineAndCharacterOfPosition(pos);
77+
public getSourceLocation(options: IGetSourceLocationOptions): ISourceLocation {
78+
const lineAndCharacter: ts.LineAndCharacter = options.sourceFile.getLineAndCharacterOfPosition(
79+
options.pos
80+
);
6981
const sourceLocation: ISourceLocation = {
70-
sourceFilePath: sourceFile.fileName,
82+
sourceFilePath: options.sourceFile.fileName,
7183
sourceFileLine: lineAndCharacter.line + 1,
7284
sourceFileColumn: lineAndCharacter.character + 1
7385
};
7486

75-
if (useDtsLocation) {
87+
if (options.useDtsLocation) {
7688
return sourceLocation;
7789
}
7890

0 commit comments

Comments
 (0)