Example #1
0
 private async getDefinitionsForFeatureAtPosition(
     url: string, position: SourcePosition,
     analysis?: Analysis): Promise<SourceRange[]> {
   analysis = analysis ||
       await this.analyzer.analyze([url], {reason: 'get definitions'});
   const featureResult =
       await this.featureFinder.getFeatureAt(url, position, analysis);
   if (!featureResult) {
     return [];
   }
   const {feature} = featureResult;
   if (feature instanceof CssCustomPropertyUse ||
       feature instanceof CssCustomPropertyAssignment) {
     const assignments = analysis.getFeatures({
       kind: 'css-custom-property-assignment',
       id: feature.name,
       externalPackages: true
     });
     return [...assignments].map((a) => a.sourceRange);
   }
   if (feature instanceof DatabindingFeature) {
     if (feature.property && feature.property.sourceRange) {
       return [feature.property.sourceRange];
     }
     return [];
   }
   if (feature.sourceRange) {
     return [feature.sourceRange];
   }
   return [];
 }
Example #2
0
export function getAnalysisDocument(analysis: Analysis, url: string): Document {
  const result = analysis.getDocument(url);
  if (result.successful) {
    return result.value;
  }
  if (result.error) {
    const message = `Unable to get document ${url}: ${result.error.message}`;
    throw new Error(message);
  }
  throw new Error(`Unable to get document ${url}`);
}
Example #3
0
/**
 * Get all namespace names for an analysis object.
 */
function getNamespaceNames(analysis: Analysis) {
  return IterableX
      .from(analysis.getFeatures(
          {kind: 'namespace', externalPackages: true, imported: true}))
      .map((n) => {
        const name = n.name;
        if (name.startsWith('window.')) {
          return name.slice('window.'.length);
        }
        return name;
      });
}