Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Apr 29, 2019
0 parents commit a548e9e
Show file tree
Hide file tree
Showing 26 changed files with 6,909 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[*]
insert_final_newline = true
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{json,js,yml}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
coverage/
.nyc_output/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.test.js
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package.json
package-lock.json
dist/
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
language: node_js
node_js: '10'
cache: yarn
env:
global:
- FORCE_COLOR=1
install:
- yarn
jobs:
include:
- stage: test
script:
- yarn run prettier-check
- yarn run tslint
- yarn run build
- yarn test
- nyc report --reporter json
- 'bash <(curl -s https://codecov.io/bash)'
- stage: release
script:
- yarn run build
- yarn run semantic-release
stages:
- test
- name: release
if: branch = master AND type = push AND fork = false
branches:
only:
- master
- /^renovate\//
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Sourcegraph

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# @sourcegraph/extension-api-classes

[![npm](https://img.shields.io/npm/v/@sourcegraph/extension-api-classes.svg)](https://www.npmjs.com/package/@sourcegraph/extension-api-classes)
[![downloads](https://img.shields.io/npm/dt/@sourcegraph/extension-api-classes.svg)](https://www.npmjs.com/package/@sourcegraph/extension-api-classes)
[![build](https://travis-ci.org/sourcegraph/extension-api-classes.svg?branch=master)](https://travis-ci.org/sourcegraph/extension-api-classes)
[![codecov](https://codecov.io/gh/sourcegraph/extension-api-classes/branch/master/graph/badge.svg?token=k6ajjWygaW)](https://codecov.io/gh/sourcegraph/extension-api-classes)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

Classes used by the Sourcegraph extension API

## Install

```
npm install @sourcegraph/extension-api-classes
# or
yarn add @sourcegraph/extension-api-classes
```

## Build

```
yarn
yarn build
```

## Test

```
yarn test
```

## Release

Releases are done automatically in CI when commits are merged into master by analyzing [Conventional Commit Messages](https://conventionalcommits.org/).
After running `yarn`, commit messages will be linted automatically when committing though a git hook.
The git hook can be circumvented for fixup commits with [git's `fixup!` autosquash feature](https://fle.github.io/git-tip-keep-your-branch-clean-with-fixup-and-autosquash.html), or by passing `--no-verify` to `git commit`.
You may have to rebase a branch before merging to ensure it has a proper commit history, or squash merge with a manually edited commit message that conforms to the convention.
72 changes: 72 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "@sourcegraph/extension-api-classes",
"description": "Classes used by the Sourcegraph extension API",
"version": "0.0.0-DEVELOPMENT",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/sourcegraph/extension-api-classes.git"
},
"files": [
"dist"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "nyc mocha",
"semantic-release": "semantic-release",
"prettier": "prettier '**/{*.{js?(on),ts?(x),scss},.*.js?(on)}' --write --list-different",
"prettier-check": "npm run prettier -- --write=false",
"tslint": "tslint -c tslint.json -p tsconfig.json './src/*.ts?(x)' './*.ts?(x)'",
"build": "tsc -p .",
"watch": "tsc -p . -w"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"mocha": {
"require": "ts-node/register",
"spec": "src/**/*.test.ts",
"ui": "tdd"
},
"nyc": {
"include": [
"src/**/*.ts?(x)"
],
"exclude": [
"**/*.test.ts?(x)"
],
"extension": [
".tsx",
".ts"
]
},
"peerDependencies": {
"sourcegraph": "*"
},
"devDependencies": {
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"@sourcegraph/extension-api-types": "^2.0.0",
"@sourcegraph/prettierrc": "^2.2.0",
"@sourcegraph/tsconfig": "^4.0.0",
"@sourcegraph/tslint-config": "^13.1.0",
"@types/mocha": "^5.2.6",
"husky": "^2.1.0",
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"prettier": "^1.17.0",
"semantic-release": "^15.13.3",
"sourcegraph": "^23.0.0",
"ts-node": "^8.1.0",
"tslint": "^5.16.0",
"typescript": "^3.4.5"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS"
}
}
}
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@sourcegraph/prettierrc')
3 changes: 3 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["github>sourcegraph/renovate-config"]
}
17 changes: 17 additions & 0 deletions src/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* istanbul ignore file */
// tslint:disable: no-object-literal-type-assertion https://github.com/palantir/tslint/issues/4628

import * as sourcegraph from 'sourcegraph'

export const MarkupKind: typeof sourcegraph.MarkupKind = {
PlainText: 'plaintext' as sourcegraph.MarkupKind.PlainText,
Markdown: 'markdown' as sourcegraph.MarkupKind.Markdown,
} as const

export const NotificationType = {
Error: 1,
Warning: 2,
Info: 3,
Log: 4,
Success: 5,
} as const
6 changes: 6 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function illegalArgument(name?: string): Error {
if (name) {
return new Error(`Illegal argument: ${name}`)
}
return new Error('Illegal argument')
}
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './location'
export * from './position'
export * from './range'
export * from './selection'
export * from './enums'
17 changes: 17 additions & 0 deletions src/location.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Location } from './location'
import { Position } from './position'
import { Range } from './range'
import { assertToJSON } from './testHelpers'

suite('Location', () => {
test('toJSON', () => {
assertToJSON(new Location(new URL('file:///u.ts'), new Position(3, 4)), {
uri: 'file:///u.ts',
range: { start: { line: 3, character: 4 }, end: { line: 3, character: 4 } },
})
assertToJSON(new Location(new URL('file:///u.ts'), new Range(1, 2, 3, 4)), {
uri: 'file:///u.ts',
range: { start: { line: 1, character: 2 }, end: { line: 3, character: 4 } },
})
})
})
37 changes: 37 additions & 0 deletions src/location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as sourcegraph from 'sourcegraph'
import { Position } from './position'
import { Range } from './range'
import { isURL } from './url'

export class Location implements sourcegraph.Location {
public static isLocation(thing: any): thing is sourcegraph.Location {
if (thing instanceof Location) {
return true
}
if (!thing) {
return false
}
return Range.isRange((thing as Location).range) && isURL((thing as Location).uri)
}

public readonly range?: sourcegraph.Range

constructor(public readonly uri: URL, rangeOrPosition?: sourcegraph.Range | sourcegraph.Position) {
if (!rangeOrPosition) {
// that's OK
} else if (rangeOrPosition instanceof Range) {
this.range = rangeOrPosition
} else if (rangeOrPosition instanceof Position) {
this.range = new Range(rangeOrPosition, rangeOrPosition)
} else {
throw new Error('Illegal argument')
}
}

public toJSON(): any {
return {
uri: this.uri,
range: this.range,
}
}
}
Loading

0 comments on commit a548e9e

Please sign in to comment.