Skip to content
Open
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 snapshots/output/diagnostics/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition diagnostics 0.0.1 `index.ts`/

/** @deprecated This class is deprecated */
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/enclosing-ranges-ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition enclosing-ranges-ts 1.0.0 `index.ts`/

// format-options: showRanges
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/enclosing-ranges/range.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language JavaScript
// < definition enclosing-ranges 0.0.1 `range.js`/

// format-options: showRanges
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/invalid-package-json/packages/a/src/a.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition @example/a HEAD src/`a.ts`/

export function a(): string {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/multi-project/packages/a/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition @example/a 1.0.0 src/`index.ts`/
//documentation ```ts
// > module "index.ts"
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/multi-project/packages/b/src/b.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition @example/b 1.0.0 src/`b.ts`/

import { a } from '@example/a/src'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/pnpm-workspaces/packages/a/src/a.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition @example/a 1.0.0 src/`a.ts`/

export function a(): string {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/pnpm-workspaces/packages/b/src/b.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition @example/b 1.0.0 src/`b.ts`/

import { a } from '@example/a'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/pure-js/src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language JavaScript
// < definition pure-js 1.0.0 src/`main.js`/

function fib(n) {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/react/src/LoaderInput.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScriptReact
// < definition react-example 1.0.0 src/`LoaderInput.tsx`/

import React from 'react'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/react/src/MyTSXElement.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScriptReact
// < definition react-example 1.0.0 src/`MyTSXElement.tsx`/

import React from 'react'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/react/src/UseMyTSXElement.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScriptReact
// < definition react-example 1.0.0 src/`UseMyTSXElement.tsx`/

import React from "react";
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/ClassWithPrivate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`ClassWithPrivate.ts`/

export class ClassWithPrivate {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/accessors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`accessors.ts`/

class C {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/class.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`class.ts`/

export class Class {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/conflicting-const-interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`conflicting-const-interface.ts`/

export const ConflictingConst = 42
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/constructor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`constructor.ts`/

namespace Yay {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`decorators.ts`/

import { Configuration } from './reusable-types'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/destructuring.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`destructuring.ts`/

interface Props {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/enum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`enum.ts`/

export enum Enum {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/function.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`function.ts`/

export function newFunction(): void {}
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/import.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`import.ts`/

import * as namespace from './namespace'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/inheritance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`inheritance.ts`/

import { Superinterface } from './reusable-types'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`interface.ts`/

export interface Interface {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/issue-45.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`issue-45.d.ts`/

export namespace example {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/local.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`local.ts`/

export function local(): string {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/module.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`module.d.ts`/

declare module 'a:b' {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`namespace.ts`/

export declare namespace a {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`object-literals-arrow-function.ts`/

import { Option } from './reusable-types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`object-literals-call-signatures.ts`/

import {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/object-literals-nested.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`object-literals-nested.ts`/

import { Option } from './reusable-types'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/object-literals.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`object-literals.ts`/

import { Configuration } from './reusable-types'
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/overload.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`overload.d.ts`/

export interface Overloader {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`property-assignment-reference.ts`/

import {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/property-assignment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`property-assignment.ts`/

export function propertyAssignment() {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/reusable-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`reusable-types.ts`/

// Reusable types for other snapshot tests
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/string-literals.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`string-literals.ts`/

interface SomeInterface {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/structural-type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`structural-type.ts`/

export function foo(): Promise<{ member: number }> {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/symbol-kinds.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`symbol-kinds.ts`/
//kind File

Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/type-alias.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`type-alias.ts`/

type S = string
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/type-parameter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`type-parameter.ts`/

export function typeParameter<A, B>(parameter: A, parameter2: B): [A, B] {
Expand Down
1 change: 1 addition & 0 deletions snapshots/output/syntax/src/typings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// language TypeScript
// < definition syntax 1.0.0 src/`typings.ts`/

export function process() {
Expand Down
15 changes: 14 additions & 1 deletion src/ProjectIndexer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from 'uvu'
import * as assert from 'uvu/assert'

import { prettyMilliseconds } from './ProjectIndexer'
import { languageForFileName, prettyMilliseconds } from './ProjectIndexer'

function minute(x: number): number {
return x * 60 * 1000
Expand All @@ -24,4 +24,17 @@ test('prettyMilliseconds', () => {
assert.is(prettyMilliseconds(minute(5) + second(8) + 999), '5m 8s 999ms')
})

test('languageForFileName', () => {
assert.is(languageForFileName('index.ts'), 'TypeScript')
assert.is(languageForFileName('index.mts'), 'TypeScript')
assert.is(languageForFileName('index.cts'), 'TypeScript')
assert.is(languageForFileName('index.tsx'), 'TypeScriptReact')
assert.is(languageForFileName('index.js'), 'JavaScript')
assert.is(languageForFileName('index.mjs'), 'JavaScript')
assert.is(languageForFileName('index.cjs'), 'JavaScript')
assert.is(languageForFileName('index.jsx'), 'JavaScriptReact')
assert.is(languageForFileName('package.json'), 'JSON')
assert.is(languageForFileName('Component.svelte'), '')
})

test.run()
17 changes: 17 additions & 0 deletions src/ProjectIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class ProjectIndexer {
}
}
const document = new scip.scip.Document({
language: languageForFileName(sourceFile.fileName),
relative_path: path.relative(this.options.cwd, sourceFile.fileName),
occurrences: [],
})
Expand Down Expand Up @@ -171,6 +172,22 @@ export class ProjectIndexer {
}
}

export function languageForFileName(fileName: string): string {
// Document.language uses the exact names from SCIP's Language enum, not the
// lowercase language identifiers used by editors.
const extension = path.extname(fileName).toLowerCase()
if (extension === '.tsx') return 'TypeScriptReact'
if (extension === '.ts' || extension === '.mts' || extension === '.cts') {
return 'TypeScript'
}
if (extension === '.jsx') return 'JavaScriptReact'
if (extension === '.js' || extension === '.mjs' || extension === '.cjs') {
return 'JavaScript'
}
if (extension === '.json') return 'JSON'
return ''
}

export function prettyMilliseconds(milliseconds: number): string {
let ms = Math.floor(milliseconds)
let result = ''
Expand Down
2 changes: 1 addition & 1 deletion src/SnapshotTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function formatSnapshot(
doc: scip.Document,
externalSymbols: scip.SymbolInformation[] = []
): string {
const out: string[] = []
const out: string[] = [`${commentSyntax} language ${doc.language}\n`]
const symbolTable = getSymbolTable(doc)

const externalSymbolTable: Map<string, scip.SymbolInformation> = new Map()
Expand Down
4 changes: 4 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ for (const snapshotDirectory of snapshotDirectories) {
throw new Error('empty LSIF index')
}
for (const document of index.documents) {
assert.ok(
document.language,
`${document.relative_path} should have a SCIP document language`
)
if (document.relative_path === 'src/symbol-kinds.ts') {
assert.equal(
document.symbols
Expand Down
Loading